function widget($args, $instance) { $map_ok = true; wp_enqueue_script('googlemaps'); $title = $instance['title']; $address = $instance['address']; $coordinates = $instance['coordinates']; $zoom = $instance['zoom']; $height = preg_replace("/[^0-9]/", "", $instance['height']); if (!$height) { $height = 250; } if (trim($address) || trim($coordinates)) { echo ts_essentials_escape($args['before_widget']); if (!empty($title)) { echo ts_essentials_escape($args['before_title'] . apply_filters('widget_title', $title) . $args['after_title']); } if (!$address) { _e('Address was not specified', 'ThemeStockyard'); return false; } if (!$coordinates) { $coordinates = ts_essentials_get_map_coordinates($address); if (is_array($coordinates)) { $coordinates = $coordinates['lat'] . ',' . $coordinates['lng']; } else { $map_ok = false; echo esc_html($coordinates); //return false; } } if ($map_ok) { $map_id_num = rand(1, 100); echo '<div id="map_canvas_' . esc_attr($map_id_num) . '_wrap" class="flexible-map" style="width:100%;height:' . esc_attr($height) . 'px" data-height="' . $height . 'px">'; echo '<input class="location" type="hidden" value="' . esc_attr($address) . '" />'; echo '<input class="coordinates" type="hidden" value="' . esc_attr($coordinates) . '" />'; echo '<input class="zoom" type="hidden" value="' . esc_attr($zoom) . '" />'; echo '<div id="map_canvas_' . esc_attr($map_id_num) . '" class="map_canvas" style="width:100%;height:' . esc_attr($height) . 'px"> </div>'; echo '</div>'; } echo ts_essentials_escape($args['after_widget']); } }
function ts_googlemap_shortcode($atts, $content = null) { $atts = shortcode_atts(array('address' => '', 'coordinates' => '', 'zoom' => '15', 'height' => '300px', 'hue' => '', 'scrollwheel' => 'disabled'), $atts); extract($atts); wp_enqueue_script('googlemaps'); $out = ''; if (!$address && !$coordinates) { $out .= __('Address was not specified', 'ThemeStockyard'); return $out; } if (!$coordinates) { $coordinates = ts_essentials_get_map_coordinates($address); if (is_array($coordinates)) { $coordinates = $coordinates['lat'] . ',' . $coordinates['lng']; } else { $out .= __('Wrong coordinates', 'ThemeStockyard'); return $out; } } $height = 'height:' . preg_replace("/[^0-9]*/", "", $atts['height']) . 'px'; $data = ''; $data .= $atts['hue'] ? ' data-hue="' . esc_attr($atts['hue']) . '"' : ''; $data .= in_array($atts['scrollwheel'], array('enabled', 'yes', '1', 'true', 'on')) ? ' data-scrollwheel="enabled"' : ''; $out .= '<div id="map_canvas_' . rand(1, 100) . '" class="flexible-map ts-shortcode-block" style="' . esc_attr($height) . '" ' . $data . '>'; $out .= '<input class="location" type="hidden" value="' . esc_attr($address) . '" />'; $out .= '<input class="coordinates" type="hidden" value="' . esc_attr($coordinates) . '" />'; $out .= '<input class="zoom" type="hidden" value="' . esc_attr($zoom) . '" />'; $out .= '<div class="map_canvas"></div>'; $out .= '</div>'; return $out; }