diff --git a/inc/api/functions.php b/inc/api/functions.php index 84e996d5..ede19273 100644 --- a/inc/api/functions.php +++ b/inc/api/functions.php @@ -139,10 +139,21 @@ function opalestate_api_get_property_data( $property_info ) { $property['labels'] = $data->get_labels(); $property['locations'] = $data->get_locations(); $property['facilities'] = $data->get_facilities(); - $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_data(); + + $amenities = $data->get_amenities(); + $amenities_result = []; + if ( $amenities ) { + foreach ( $amenities as $amenity ) { + $value = has_term( $amenity->term_id, 'opalestate_amenities', $property_info->ID ); + $amenity->value = $value; + $amenities_result[] = $amenity; + } + } + + $property['amenities'] = $amenities_result; + $property['types'] = $data->get_types_tax(); + $property['author_type'] = $data->get_author_type(); + $property['author_data'] = $data->get_author_link_data(); $limit = opalestate_get_option( 'single_views_statistics_limit', 8 ); $stats = new Opalestate_View_Stats( $data->get_id(), $limit ); diff --git a/inc/api/v1/property.php b/inc/api/v1/property.php index b9fc76e2..e7f8e8dd 100644 --- a/inc/api/v1/property.php +++ b/inc/api/v1/property.php @@ -366,7 +366,7 @@ class Opalestate_Property_Api extends Opalestate_Base_API { [ 'taxonomy' => 'opalestate_amenities', 'field' => 'slug', - 'terms' => sanitize_text_field( $request['amenities'] ), + 'terms' => ( $request['amenities'] ), ]; } @@ -376,29 +376,46 @@ class Opalestate_Property_Api extends Opalestate_Base_API { } $args['meta_query'] = [ 'relation' => 'AND' ]; - if ( isset( $request['info'] ) && is_array( $request['info'] ) ) { - $metaquery = []; - foreach ( $request['info'] as $key => $value ) { - if ( trim( $value ) ) { - if ( is_numeric( trim( $value ) ) ) { - $fieldquery = [ - 'key' => OPALESTATE_PROPERTY_PREFIX . $key, - 'value' => sanitize_text_field( trim( $value ) ), - 'compare' => apply_filters( 'opalestate_info_numeric_compare', '>=' ), - 'type' => 'NUMERIC', - ]; - } else { - $fieldquery = [ - 'key' => OPALESTATE_PROPERTY_PREFIX . $key, - 'value' => sanitize_text_field( trim( $value ) ), - 'compare' => 'LIKE', - ]; - } - $sarg = apply_filters( 'opalestate_search_field_query_' . $key, $fieldquery ); - $metaquery[] = $sarg; + + if ( isset( $request['info'] ) ) { + $info_array = []; + if ( is_array( $request['info'] ) ) { + $info_array = $request['info']; + } elseif ( is_string( $request['info'] ) ) { + $info = $request['info']; + $array = json_decode($info); + $array = json_decode(json_encode($array), true); + + if ( is_array( $array ) ) { + $info_array = $array; } } - $args['meta_query'] = array_merge( $args['meta_query'], $metaquery ); + + if ( $info_array && ! empty($info_array) ) { + $metaquery = []; + foreach ( $info_array as $key => $value ) { + if ( trim( $value ) ) { + if ( is_numeric( trim( $value ) ) ) { + $fieldquery = [ + 'key' => OPALESTATE_PROPERTY_PREFIX . $key, + 'value' => sanitize_text_field( trim( $value ) ), + 'compare' => apply_filters( 'opalestate_info_numeric_compare', '>=' ), + 'type' => 'NUMERIC', + ]; + } else { + $fieldquery = [ + 'key' => OPALESTATE_PROPERTY_PREFIX . $key, + 'value' => sanitize_text_field( trim( $value ) ), + 'compare' => 'LIKE', + ]; + } + $sarg = apply_filters( 'opalestate_search_field_query_' . $key, $fieldquery ); + $metaquery[] = $sarg; + } + } + + $args['meta_query'] = array_merge( $args['meta_query'], $metaquery ); + } } if ( $search_min_price != '' && $search_min_price != '' && is_numeric( $search_min_price ) && is_numeric( $search_max_price ) ) { @@ -637,13 +654,13 @@ class Opalestate_Property_Api extends Opalestate_Base_API { 'validate_callback' => 'rest_validate_request_arg', ]; - $params['info'] = [ - 'description' => __( 'Info', 'opalestate-pro' ), - 'type' => 'array', - // 'default' => '', - // 'sanitize_callback' => 'sanitize_text_field', - 'validate_callback' => 'rest_validate_request_arg', - ]; + // $params['info'] = [ + // 'description' => __( 'Info', 'opalestate-pro' ), + // 'type' => 'array', + // // 'default' => '', + // // 'sanitize_callback' => 'sanitize_text_field', + // 'validate_callback' => 'rest_validate_request_arg', + // ]; return $params; } diff --git a/inc/property/class-metabox-property-admin.php b/inc/property/class-metabox-property-admin.php index 1b38fa0a..4b929220 100755 --- a/inc/property/class-metabox-property-admin.php +++ b/inc/property/class-metabox-property-admin.php @@ -240,7 +240,6 @@ class Opalestate_Property_MetaBox { 'name' => esc_html__( 'Regular Price', 'opalestate-pro' ) . $currency, 'type' => 'text', 'description' => esc_html__( 'Enter amount without currency', 'opalestate-pro' ), - 'attributes' => [ 'required' => 'required' ], 'before_row' => '

' . ( is_admin() ? "" : esc_html__( 'Price', 'opalestate-pro' ) ) . '

', // callback ], [ diff --git a/inc/property/class-opalestate-search.php b/inc/property/class-opalestate-search.php index 9f6365e5..46933060 100755 --- a/inc/property/class-opalestate-search.php +++ b/inc/property/class-opalestate-search.php @@ -114,7 +114,7 @@ class OpalEstate_Search { [ 'taxonomy' => 'opalestate_amenities', 'field' => 'slug', - 'terms' => sanitize_text_field( $_GET['amenities'] ), + 'terms' => ( $_GET['amenities'] ), ]; } @@ -153,7 +153,6 @@ class OpalEstate_Search { if ( $search_min_price != '' && $search_max_price != '' && is_numeric( $search_min_price ) && is_numeric( $search_max_price ) ) { if ( $search_min_price ) { - array_push( $args['meta_query'], [ 'key' => OPALESTATE_PROPERTY_PREFIX . 'price', 'value' => [ $search_min_price, $search_max_price ], diff --git a/inc/template-functions.php b/inc/template-functions.php index 3a6a6ea9..a43d73e8 100755 --- a/inc/template-functions.php +++ b/inc/template-functions.php @@ -10,6 +10,33 @@ if ( ! defined( 'ABSPATH' ) ) { exit; // Exit if accessed directly } +/** + * Add body classes for Opalestate pages. + * + * @param array $classes Body Classes. + * @return array + */ +function opalestate_body_class( $classes ) { + $classes = (array) $classes; + + $classes[] = 'opalestate-active'; + + if ( is_user_logged_in() ) { + $current_user = wp_get_current_user(); + + if ( $current_user ) { + $roles = $current_user->roles; + if ( $roles && is_array( $roles ) ) { + foreach ( $roles as $role ) { + $classes[] = 'opalestate-role-' . esc_attr( $role ); + } + } + } + } + + return array_unique( $classes ); +} + function opalestate_archive_search_block() { echo opalestate_load_template_path( 'parts/archive-search-block' ); } diff --git a/inc/template-hook-functions.php b/inc/template-hook-functions.php index 6d15ae61..697c64f4 100755 --- a/inc/template-hook-functions.php +++ b/inc/template-hook-functions.php @@ -1,4 +1,9 @@
+ + ', '' ); ?> + +
@@ -88,6 +92,8 @@ $header = apply_filters( 'opalestate_single_show_heading', true );
    + + get_sku() ) : ?>
  • @@ -103,6 +109,8 @@ $header = apply_filters( 'opalestate_single_show_heading', true );
  • + +
diff --git a/templates/content-single-property-v3.php b/templates/content-single-property-v3.php index fd543e36..c345c7cc 100755 --- a/templates/content-single-property-v3.php +++ b/templates/content-single-property-v3.php @@ -13,6 +13,8 @@ $header = apply_filters( 'opalestate_single_show_heading', true );
    + +
  • @@ -24,6 +26,8 @@ $header = apply_filters( 'opalestate_single_show_heading', true );
  • + +
@@ -38,10 +42,14 @@ $header = apply_filters( 'opalestate_single_show_heading', true );
+ + ', '' ); ?> + +
diff --git a/templates/content-single-property-v4.php b/templates/content-single-property-v4.php index 18fff383..9c65b6e1 100755 --- a/templates/content-single-property-v4.php +++ b/templates/content-single-property-v4.php @@ -11,10 +11,14 @@ $header = apply_filters( 'opalestate_single_show_heading', true );
+ + ', '' ); ?> + +
@@ -58,6 +62,8 @@ $header = apply_filters( 'opalestate_single_show_heading', true );
    + + get_sku() ) : ?>
  • @@ -73,6 +79,8 @@ $header = apply_filters( 'opalestate_single_show_heading', true );
  • + +
diff --git a/templates/content-single-property-v5.php b/templates/content-single-property-v5.php index 60ac1a5d..e1ca823d 100755 --- a/templates/content-single-property-v5.php +++ b/templates/content-single-property-v5.php @@ -51,10 +51,14 @@ $header = apply_filters( 'opalestate_single_show_heading', true );
+ + ', '' ); ?> + +
@@ -91,6 +95,8 @@ $header = apply_filters( 'opalestate_single_show_heading', true );
    + + get_sku() ) : ?>
  • @@ -103,6 +109,8 @@ $header = apply_filters( 'opalestate_single_show_heading', true );
  • + +
diff --git a/templates/content-single-property.php b/templates/content-single-property.php index efbe5f5c..f54ee9a6 100755 --- a/templates/content-single-property.php +++ b/templates/content-single-property.php @@ -9,10 +9,14 @@ $header = apply_filters( 'opalestate_single_show_heading', true );
+ + ', '' ); ?> + +
@@ -63,6 +67,8 @@ $header = apply_filters( 'opalestate_single_show_heading', true );
    + + get_sku() ) : ?>
  • @@ -78,6 +84,8 @@ $header = apply_filters( 'opalestate_single_show_heading', true );
  • + +