'property', 'posts_per_page' => -1, 'post_status' => 'publish', 'meta_query' => array( array( 'key' => '_on_market', 'value' => 'yes' ), array( 'key' => '_featured', 'value' => 'yes' ) ), 'fields' => 'id=>parent' ) ); $featured_property_ids = array_keys( $featured ); set_transient( 'ph_featured_properties', $featured_property_ids, YEAR_IN_SECONDS ); return $featured_property_ids; } /** * Get the placeholder image URL for properties * * @access public * @return string */ function ph_placeholder_img_src() { return apply_filters( 'propertyhive_placeholder_img_src', PH()->plugin_url() . '/assets/images/placeholder.png' ); } /** * Get the placeholder image * * @access public * @return string */ function ph_placeholder_img( $size = 'thumbnail' ) { $dimensions = ph_get_image_size( $size ); return apply_filters('propertyhive_placeholder_img', 'Placeholder' ); } /** * Track property views */ function ph_track_property_view() { if ( ! is_singular( 'property' ) ) return; global $post; // Track in cookie if ( apply_filters( 'propertyhive_store_in_recently_viewed_cookie', true ) ) { if ( empty( $_COOKIE['propertyhive_recently_viewed'] ) ) $viewed_properties = array(); else $viewed_properties = (array) explode( '|', $_COOKIE['propertyhive_recently_viewed'] ); if ( ! in_array( $post->ID, $viewed_properties ) ) $viewed_properties[] = $post->ID; if ( sizeof( $viewed_properties ) > 15 ) array_shift( $viewed_properties ); // Store for session only ph_setcookie( 'propertyhive_recently_viewed', implode( '|', $viewed_properties ) ); } // Track in database if ( !is_user_logged_in() || ( is_user_logged_in() && !current_user_can('manage_propertyhive') ) ) { // User isn't logged in $view_counts = get_post_meta( $post->ID, '_view_statistics', TRUE ); if ( $view_counts == '' || !is_array($view_counts) ) { $view_counts = array(); } if ( !isset($view_counts[date("Y-m-d")]) ) { $view_counts[date("Y-m-d")] = 0; } ++$view_counts[date("Y-m-d")]; update_post_meta( $post->ID, '_view_statistics', $view_counts ); } } add_action( 'template_redirect', 'ph_track_property_view', 20 ); function get_property_map( $args = array() ) { global $property; if ( $property->latitude != '' && $property->latitude != '0' && $property->longitude != '' && $property->longitude != '0' ) { $id_suffix = ( ( isset($args['id']) && $args['id'] != '' ) ? '_' . $args['id'] : '' ); if ( get_option('propertyhive_maps_provider') == 'mapbox' ) { echo '
'; $assets_path = str_replace( array( 'http:', 'https:' ), '', PH()->plugin_url() ) . '/assets/js/mapbox/'; wp_register_style('mapbox', $assets_path . 'mapbox-gl.css', array(), '3.8.0'); wp_enqueue_style('mapbox'); wp_register_script('mapbox', $assets_path . 'mapbox-gl.js', array(), '3.8.0', false); wp_enqueue_script('mapbox'); ?> '; $assets_path = str_replace( array( 'http:', 'https:' ), '', PH()->plugin_url() ) . '/assets/js/leaflet/'; wp_register_style('leaflet', $assets_path . 'leaflet.css', array(), '1.9.4'); wp_enqueue_style('leaflet'); wp_register_script('leaflet', $assets_path . 'leaflet.js', array(), '1.9.4', false); wp_enqueue_script('leaflet'); ?> latitude . ',' . $property->longitude ) . '"> '; } else { echo '
'; wp_register_script('googlemaps', '//maps.googleapis.com/maps/api/js?' . ( ( $api_key != '' && $api_key !== FALSE ) ? 'key=' . $api_key : '' ), false, '3'); wp_enqueue_script('googlemaps'); ?> latitude != '' && $property->latitude != '0' && $property->longitude != '' && $property->longitude != '0' ) { $api_key = get_option('propertyhive_google_maps_api_key'); $id_suffix = ( ( isset($args['id']) && $args['id'] != '' ) ? '_' . $args['id'] : '' ); $link = ( ( isset($args['link']) && ($args['link'] === 'false' || $args['link'] === FALSE) ) ? 'false' : 'true' ); $map_url = 'https://maps.googleapis.com/maps/api/staticmap?' . 'center=' . (float)$property->latitude . ',' . (float)$property->longitude . '&size=1024x' . str_replace( "px", "", ( ( isset($args['height']) && !empty($args['height']) && is_numeric($args['height']) ) ? (int)$args['height'] : '400' ) ) . '&zoom=' . ( ( isset($args['zoom']) && !empty($args['zoom']) ) ? (int)$args['zoom'] : '14' ) . '&maptype=roadmap' . '&markers=%7C%7C' . (float)$property->latitude . ',' . (float)$property->longitude . '&key=' . urlencode($api_key); echo ''; if ( $link === true ) { echo ''; } else { echo '
'; } } } } function get_property_street_view( $args = array() ) { global $property; if ( get_option('propertyhive_maps_provider') == 'osm' || get_option('propertyhive_maps_provider') == 'mapbox' ) { } else { if ( $property->latitude != '' && $property->latitude != '0' && $property->longitude != '' && $property->longitude != '0' ) { $api_key = get_option('propertyhive_google_maps_api_key'); if ( isset($args['embed']) && ($args['embed'] === 'true' || $args['embed'] === TRUE) ) { echo ''; } else { wp_register_script('googlemaps', '//maps.googleapis.com/maps/api/js?' . ( ( $api_key != '' && $api_key !== FALSE ) ? 'key=' . $api_key : '' ), false, '3'); wp_enqueue_script('googlemaps'); echo '
'; ?> __( 'Mains Supply', 'propertyhive' ), 'wind_turbine' => __( 'Wind Turbine', 'propertyhive' ), 'solar_pv_panels' => __( 'Solar PV Panels', 'propertyhive' ), 'private_supply' => __( 'Private Supply', 'propertyhive' ), ); $types = apply_filters( 'propertyhive_electricity_types', $types ); asort($types); $types['other'] = __( 'Other', 'propertyhive' ); return $types; } function get_electricity_type( $type ) { $types = get_electricity_types(); if ( isset($types[$type]) ) { return $types[$type]; } return ''; } function get_water_types() { $types = array( 'mains_supply' => __( 'Mains Supply', 'propertyhive' ), 'private_supply' => __( 'Private Supply', 'propertyhive' ), ); $types = apply_filters( 'propertyhive_water_types', $types ); asort($types); $types['other'] = __( 'Other', 'propertyhive' ); return $types; } function get_water_type( $type ) { $types = get_water_types(); if ( isset($types[$type]) ) { return $types[$type]; } return ''; } function get_broadband_types() { $types = array( 'adsl' => __( 'ADSL', 'propertyhive' ), 'cable' => __( 'Cable', 'propertyhive' ), 'fttc' => __( 'FTTC (Fibre to the Cabinet)', 'propertyhive' ), 'fttp' => __( 'FTTP (Fibre to the Premises)', 'propertyhive' ), 'none' => __( 'None', 'propertyhive' ), ); $types = apply_filters( 'propertyhive_broadband_types', $types ); asort($types); $types['other'] = __( 'Other', 'propertyhive' ); return $types; } function get_broadband_type( $type ) { $types = get_broadband_types(); if ( isset($types[$type]) ) { return $types[$type]; } return ''; } function get_heating_types() { $types = array( 'air_conditioning' => __( 'Air Conditioning', 'propertyhive' ), 'central' => __( 'Central Heating', 'propertyhive' ), 'double_glazing' => __( 'Double Glazing', 'propertyhive' ), 'eco_friendly' => __( 'Eco-Friendly', 'propertyhive' ), 'electric' => __( 'Electric Heating', 'propertyhive' ), 'gas' => __( 'Gas Heating', 'propertyhive' ), 'gas_central' => __( 'Gas Central Heating', 'propertyhive' ), 'night_storage' => __( 'Night Storage Heating', 'propertyhive' ), 'oil' => __( 'Oil Heating', 'propertyhive' ), 'solar' => __( 'Solar Panels', 'propertyhive' ), 'solar_water' => __( 'Solar Water Heating', 'propertyhive' ), 'under_floor' => __( 'Underfloor Heating', 'propertyhive' ), 'wood_burner' => __( 'Wood Burner', 'propertyhive' ), 'open_fire' => __( 'Open Fire', 'propertyhive' ), 'biomass_boiler' => __( 'Biomass Boiler', 'propertyhive' ), 'ground_source_heat_pump' => __( 'Ground Source Heat Pump', 'propertyhive' ), 'air_source_heat_pump' => __( 'Air Source Heat Pump', 'propertyhive' ), 'solar_pv_thermal' => __( 'Solar PV Thermal', 'propertyhive' ), 'solar_thermal' => __( 'Solar Thermal Heating', 'propertyhive' ), ); $types = apply_filters( 'propertyhive_heating_types', $types ); asort($types); $types['other'] = __( 'Other', 'propertyhive' ); return $types; } function get_heating_type( $type ) { $types = get_heating_types(); if ( isset($types[$type]) ) { return $types[$type]; } return ''; } function get_sewerage_types() { $types = array( 'mains_supply' => __( 'Mains Supply', 'propertyhive' ), 'private_supply' => __( 'Private Supply', 'propertyhive' ), ); $types = apply_filters( 'propertyhive_sewerage_types', $types ); asort($types); $types['other'] = __( 'Other', 'propertyhive' ); return $types; } function get_sewerage_type( $type ) { $types = get_sewerage_types(); if ( isset($types[$type]) ) { return $types[$type]; } return ''; } function get_flooding_source_types() { $types = array( 'river' => __( 'River', 'propertyhive' ), 'sea' => __( 'Sea', 'propertyhive' ), 'groundwater' => __( 'Groundwater', 'propertyhive' ), 'lake' => __( 'Lake', 'propertyhive' ), 'reservoir' => __( 'Reservoir', 'propertyhive' ), ); $types = apply_filters( 'propertyhive_flooding_source_types', $types ); asort($types); $types['other'] = __( 'Other', 'propertyhive' ); return $types; } function get_flooding_source_type( $type ) { $types = get_flooding_source_types(); if ( isset($types[$type]) ) { return $types[$type]; } return ''; } function get_accessibility_types() { $types = array( 'lateral_living' => __( 'Lateral Living', 'propertyhive' ), 'level_access' => __( 'Level Access', 'propertyhive' ), 'lift_access' => __( 'Lift Access', 'propertyhive' ), 'step_free_access' => __( 'Step-Free Access', 'propertyhive' ), 'wet_room' => __( 'Wet Room', 'propertyhive' ), 'level_access_shower' => __( 'Level Access Shower', 'propertyhive' ), 'wide_doorways' => __( 'Wide Doorways', 'propertyhive' ), 'ramped_access' => __( 'Ramped Access', 'propertyhive' ), 'unsuitableForWheelchairs' => __( 'Unsuitable for Wheelchairs', 'propertyhive' ), ); $types = apply_filters( 'propertyhive_accessibility_types', $types ); asort($types); $types['other'] = __( 'Other', 'propertyhive' ); return $types; } function get_accessibility_type( $type ) { $types = get_accessibility_types(); if ( isset($types[$type]) ) { return $types[$type]; } return ''; } function get_restrictions() { $types = array( 'conservation_area' => __( 'Restrictions due to being in a conservation area', 'propertyhive' ), 'lease_restrictions' => __( 'Restrictions in the lease', 'propertyhive' ), 'listed_building' => __( 'Restrictions due to being listed', 'propertyhive' ), 'permitted_development' => __( 'Restrictions on property development', 'propertyhive' ), 'real_burdens' => __( 'A real burden applies to this property (Scotland only)', 'propertyhive' ), 'holiday_home_rental' => __( 'Holiday home rental restrictions', 'propertyhive' ), 'restrictive_covenant' => __( 'Restrictive covenants', 'propertyhive' ), 'business_from_property' => __( 'Restrictions on running a business', 'propertyhive' ), 'property_subletting' => __( 'Restrictions regarding subletting', 'propertyhive' ), 'tree_preservation_order' => __( 'Tree preservation orders', 'propertyhive' ), ); $types = apply_filters( 'propertyhive_restrictions', $types ); asort($types); $types['other'] = __( 'Other', 'propertyhive' ); return $types; } function get_restriction( $type ) { $types = get_restrictions(); if ( isset($types[$type]) ) { return $types[$type]; } return ''; } function get_rights() { $types = array( 'right_of_way_public' => __( 'Public rights of way', 'propertyhive' ), 'right_of_way_private' => __( 'Private rights of way', 'propertyhive' ), 'registered_easements_hmlr' => __( 'Registered easements/rights with the HMLR (Land Registry)', 'propertyhive' ), 'servitudes' => __( 'Servitudes (Scotland only)', 'propertyhive' ), 'shared_driveway' => __( 'Shared driveway', 'propertyhive' ), 'loft_access' => __( 'Loft access', 'propertyhive' ), 'drain_access' => __( 'Drain access', 'propertyhive' ), ); $types = apply_filters( 'propertyhive_rights', $types ); asort($types); $types['other'] = __( 'Other', 'propertyhive' ); return $types; } function get_right( $type ) { $types = get_rights(); if ( isset($types[$type]) ) { return $types[$type]; } return ''; } add_filter( 'get_post_metadata', function ( $value, $post_id, $meta_key, $single ) { static $is_recursing = false; // Used to prevent infinite loop // Only filter if we're not recursing and if it is a post thumbnail ID if ( ! $is_recursing && $meta_key === '_thumbnail_id' && get_post_type( $post_id ) == 'property' ) { $is_recursing = true; $value = get_post_thumbnail_id( $post_id ); $is_recursing = false; if ( empty($value) ) // If we haven't already get a thumbnail ID (i.e. in the case where someone has added theme support) { $photos = get_post_meta( $post_id, '_photos', TRUE ); if ( is_array($photos) && !empty($photos) ) { $photos = array_filter( $photos ); $value = $photos[0]; } } if ( ! $single ) { $value = array( $value ); } } return $value; }, 10, 4); add_filter( 'wpseo_add_opengraph_images', function ( $object ) { if ( get_option('propertyhive_images_stored_as', '') != 'urls' ) { return $object; } global $post; if ( isset($post->post_type) && $post->post_type == 'property' ) { $property = new PH_Property($post->ID); $photos = $property->_photo_urls; if (isset($photos) && is_array($photos) && !empty($photos) && isset($photos[0]) && isset($photos[0]['url'])) { $secondary_image = array( 'url' => $photos[0]['url']/*, 'height' => 768, 'width' => 1024*/ ); $object->add_image( $secondary_image ); } } return $object; });