| 1: | <?php |
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | if ( ! defined( 'ABSPATH' ) ) { |
| 15: | exit; |
| 16: | } |
| 17: | |
| 18: | |
| 19: | |
| 20: | |
| 21: | |
| 22: | |
| 23: | |
| 24: | |
| 25: | |
| 26: | function epl_property_map_default_callback( $args ) { |
| 27: | |
| 28: | $defaults = array( |
| 29: | 'width' => '100%', |
| 30: | 'height' => '350px', |
| 31: | 'zoom' => '17', |
| 32: | ); |
| 33: | |
| 34: | $args = wp_parse_args( $args, apply_filters( 'epl_map_display_defaults', $defaults ) ); |
| 35: | |
| 36: | global $property; |
| 37: | |
| 38: | $api_key = epl_get_option( 'epl_google_api_key' ); |
| 39: | $show_warning = apply_filters( 'epl_show_map_key_warning', true ); |
| 40: | |
| 41: | if ( empty( $api_key ) ) { |
| 42: | if ( $show_warning && is_user_logged_in() && current_user_can( 'administrator' ) ) { |
| 43: | epl_map_api_key_warning(); |
| 44: | } |
| 45: | return; |
| 46: | } |
| 47: | |
| 48: | |
| 49: | if ( 'yes' === $property->get_property_meta( 'property_address_display' ) ) { |
| 50: | |
| 51: | $address = epl_property_get_the_full_address(); |
| 52: | $address = apply_filters( 'epl_map_address', $address ); |
| 53: | |
| 54: | |
| 55: | $coordinates = $property->get_property_meta( 'property_address_coordinates' ); |
| 56: | |
| 57: | echo do_shortcode( '[listing_map zoom=14 width="' . $args['width'] . '" height="' . $args['height'] . '" zoom="' . $args['zoom'] . '" cord="' . $coordinates . '" q="' . $address . '"]' ); |
| 58: | } else { |
| 59: | |
| 60: | $address = $property->get_property_meta( 'property_address_suburb' ) . ', '; |
| 61: | $address .= $property->get_property_meta( 'property_address_state' ) . ', '; |
| 62: | $address .= $property->get_property_meta( 'property_address_postal_code' ); |
| 63: | $address = apply_filters( 'epl_map_address', $address ); |
| 64: | echo do_shortcode( '[listing_map zoom=14 suburb_mode=1 q="' . $address . '"]' ); |
| 65: | } |
| 66: | } |
| 67: | add_action( 'epl_property_map', 'epl_property_map_default_callback' ); |
| 68: | |
| 69: | |
| 70: | |
| 71: | |
| 72: | |
| 73: | |
| 74: | function epl_map_api_key_warning() { |
| 75: | ?> |
| 76: | |
| 77: | <div class="epl-danger epl-warning-map-key"> |
| 78: | <p><?php esc_html_e( 'Ensure you have set a Google Maps API Key from Dashboard > Easy Property Listings > Settings.', 'easy-property-listings' ); ?> |
| 79: | <em><?php esc_html_e( 'Note: This message is only displayed to logged in administrators.', 'easy-property-listings' ); ?></em> |
| 80: | </p> |
| 81: | </div> |
| 82: | <?php |
| 83: | } |
| 84: | |