Created
May 23, 2013 21:26
-
-
Save tareq1988/5639549 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Map display shortcode | |
* | |
* @param string $meta_key | |
* @param int $post_id | |
* @param array $args | |
*/ | |
function wpuf_shortcode_map( $location, $post_id = null, $args = array() ) { | |
// compatibility | |
if ( $post_id ) { | |
wpuf_shortcode_map_post( $location, $post_id, $args ); | |
return; | |
} | |
$default = array('width' => 450, 'height' => 250, 'zoom' => 12); | |
$args = wp_parse_args( $args, $default ); | |
list( $def_lat, $def_long ) = explode( ',', $location ); | |
$def_lat = $def_lat ? $def_lat : 0; | |
$def_long = $def_long ? $def_long : 0; | |
?> | |
<div class="google-map" style="margin: 10px 0; height: <?php echo $args['height']; ?>px; width: <?php echo $args['width']; ?>px;" id="wpuf-map-<?php echo $meta_key; ?>"></div> | |
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script> | |
<script type="text/javascript"> | |
jQuery(function($){ | |
var curpoint = new google.maps.LatLng(<?php echo $def_lat; ?>, <?php echo $def_long; ?>); | |
var gmap = new google.maps.Map( $('#wpuf-map-<?php echo $meta_key; ?>')[0], { | |
center: curpoint, | |
zoom: <?php echo $args['zoom']; ?>, | |
mapTypeId: window.google.maps.MapTypeId.ROADMAP | |
}); | |
var marker = new window.google.maps.Marker({ | |
position: curpoint, | |
map: gmap, | |
draggable: true | |
}); | |
}); | |
</script> | |
<?php | |
} | |
/** | |
* Map shortcode for users | |
* | |
* @param string $meta_key | |
* @param int $user_id | |
* @param array $args | |
*/ | |
function wpuf_shortcode_map_user( $meta_key, $user_id = null, $args = array() ) { | |
$location = get_user_meta( $user_id, $meta_key, true ); | |
wpuf_shortcode_map( $location, null, $args ); | |
} | |
/** | |
* Map shortcode post posts | |
* | |
* @global object $post | |
* @param string $meta_key | |
* @param int $post_id | |
* @param array $args | |
*/ | |
function wpuf_shortcode_map_post( $meta_key, $post_id = null, $args = array() ) { | |
global $post; | |
if ( !$post_id ) { | |
$post_id = $post->ID; | |
} | |
$location = get_post_meta( $post_id, $meta_key, true ); | |
wpuf_shortcode_map( $location, null, $args ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment