calypsoify
3 years ago
carousel
3 years ago
cloudflare-analytics
4 years ago
comment-likes
5 years ago
comments
3 years ago
contact-form
1 year ago
custom-css
3 years ago
custom-post-types
3 years ago
geo-location
4 years ago
google-analytics
3 years ago
gravatar
6 years ago
infinite-scroll
3 years ago
likes
3 years ago
markdown
3 years ago
masterbar
3 years ago
memberships
3 years ago
photon
6 years ago
photon-cdn
3 years ago
plugin-search
4 years ago
post-by-email
3 years ago
related-posts
3 years ago
scan
3 years ago
seo-tools
3 years ago
sharedaddy
3 years ago
shortcodes
3 years ago
simple-payments
3 years ago
site-icon
4 years ago
sitemaps
3 years ago
sso
3 years ago
stats
3 years ago
subscriptions
3 years ago
theme-tools
3 years ago
tiled-gallery
3 years ago
verification-tools
4 years ago
videopress
3 years ago
widget-visibility
3 years ago
widgets
3 years ago
woocommerce-analytics
4 years ago
wordads
3 years ago
wpcom-block-editor
4 years ago
wpcom-tos
5 years ago
action-bar.php
3 years ago
carousel.php
4 years ago
comment-likes.php
3 years ago
comments.php
4 years ago
contact-form.php
3 years ago
copy-post.php
3 years ago
custom-content-types.php
4 years ago
custom-css.php
3 years ago
enhanced-distribution.php
4 years ago
geo-location.php
4 years ago
google-analytics.php
4 years ago
google-fonts.php
3 years ago
gravatar-hovercards.php
3 years ago
infinite-scroll.php
3 years ago
json-api.php
5 years ago
latex.php
4 years ago
lazy-images.php
4 years ago
likes.php
3 years ago
markdown.php
4 years ago
masterbar.php
4 years ago
module-extras.php
4 years ago
module-headings.php
3 years ago
module-info.php
3 years ago
monitor.php
4 years ago
notes.php
3 years ago
photon-cdn.php
3 years ago
photon.php
4 years ago
plugin-search.php
3 years ago
post-by-email.php
5 years ago
post-list.php
4 years ago
protect.php
3 years ago
publicize.php
3 years ago
related-posts.php
4 years ago
search.php
4 years ago
seo-tools.php
4 years ago
sharedaddy.php
4 years ago
shortcodes.php
3 years ago
shortlinks.php
4 years ago
sitemaps.php
4 years ago
sso.php
3 years ago
stats.php
3 years ago
subscriptions.php
3 years ago
theme-tools.php
3 years ago
tiled-gallery.php
4 years ago
vaultpress.php
4 years ago
verification-tools.php
5 years ago
videopress.php
4 years ago
waf.php
3 years ago
widget-visibility.php
4 years ago
widgets.php
3 years ago
woocommerce-analytics.php
5 years ago
wordads.php
5 years ago
wpgroho.js
6 years ago
geo-location.php
98 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Module: geo-location |
| 4 | * |
| 5 | * @package automattic/jetpack |
| 6 | */ |
| 7 | |
| 8 | /** |
| 9 | * Adds support for geo-location features. |
| 10 | */ |
| 11 | |
| 12 | require_once __DIR__ . '/geo-location/class.jetpack-geo-location.php'; |
| 13 | |
| 14 | /** |
| 15 | * Geo-location shortcode callback for display of location data associated with a post. |
| 16 | * |
| 17 | * Usage with current global $post: |
| 18 | * [geo-location] |
| 19 | * |
| 20 | * Usage with specific post ID: |
| 21 | * [geo-location post=5] |
| 22 | * |
| 23 | * @param array $attributes Shortcode attributes. |
| 24 | */ |
| 25 | function jetpack_geo_shortcode( $attributes ) { |
| 26 | $attributes = shortcode_atts( |
| 27 | array( |
| 28 | 'post' => null, |
| 29 | 'id' => null, |
| 30 | ), |
| 31 | $attributes |
| 32 | ); |
| 33 | return jetpack_geo_get_location( $attributes['post'] ? $attributes['post'] : $attributes['id'] ); |
| 34 | } |
| 35 | add_shortcode( 'geo-location', 'jetpack_geo_shortcode' ); |
| 36 | |
| 37 | /** |
| 38 | * Get the geo-location data associated with the supplied post ID, if it's available |
| 39 | * and marked as being available for public display. The returned array will contain |
| 40 | * "latitude", "longitude" and "label" keys. |
| 41 | * |
| 42 | * If you do not supply a value for $post_id, the global $post will be used, if |
| 43 | * available. |
| 44 | * |
| 45 | * @param integer|null $post_id Post ID. |
| 46 | * |
| 47 | * @return array|null |
| 48 | */ |
| 49 | function jetpack_geo_get_data( $post_id = null ) { |
| 50 | $geo = Jetpack_Geo_Location::init(); |
| 51 | |
| 52 | if ( ! $post_id ) { |
| 53 | $post_id = $geo->get_post_id(); |
| 54 | } |
| 55 | |
| 56 | $meta_values = $geo->get_meta_values( $post_id ); |
| 57 | |
| 58 | if ( ! $meta_values['is_public'] || ! $meta_values['is_populated'] ) { |
| 59 | return null; |
| 60 | } |
| 61 | |
| 62 | return array( |
| 63 | 'latitude' => $meta_values['latitude'], |
| 64 | 'longitude' => $meta_values['longitude'], |
| 65 | 'label' => $meta_values['label'], |
| 66 | ); |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Display the label HTML for the geo-location information associated with the supplied |
| 71 | * post ID. |
| 72 | * |
| 73 | * If you do not supply a value for $post_id, the global $post will be used, if |
| 74 | * available. |
| 75 | * |
| 76 | * @param integer|null $post_id Post ID. |
| 77 | * |
| 78 | * @return void |
| 79 | */ |
| 80 | function jetpack_geo_display_location( $post_id = null ) { |
| 81 | echo jetpack_geo_get_location( $post_id ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaped in `Jetpack_Geo_Location::get_location_label`. |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Return the label HTML for the geo-location information associated with the supplied |
| 86 | * post ID. |
| 87 | * |
| 88 | * If you do not supply a value for $post_id, the global $post will be used, if |
| 89 | * available. |
| 90 | * |
| 91 | * @param integer|null $post_id Post ID. |
| 92 | * |
| 93 | * @return string |
| 94 | */ |
| 95 | function jetpack_geo_get_location( $post_id = null ) { |
| 96 | return Jetpack_Geo_Location::init()->get_location_label( $post_id ); |
| 97 | } |
| 98 |