PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 7.4.3
Jetpack – WP Security, Backup, Speed, & Growth v7.4.3
12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 14.3.1 14.4.2 All 500 releases
jetpack / modules / geo-location.php
geo-location.php
82 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 require_once dirname( __FILE__ ) . '/geo-location/class.jetpack-geo-location.php';
4
5 /**
6 * Geo-location shortcode for display of location data associated with a post.
7 *
8 * Usage with current global $post:
9 * [geo-location]
10 *
11 * Usage with specific post ID:
12 * [geo-location post=5]
13 */
14 add_shortcode( 'geo-location', 'jetpack_geo_shortcode' );
15
16 function jetpack_geo_shortcode( $attributes ) {
17 $attributes = shortcode_atts( array( 'post' => null, 'id' => null ), $attributes );
18 return jetpack_geo_get_location( $attributes['post'] ? $attributes['post'] : $attributes['id'] );
19 }
20
21 /**
22 * Get the geo-location data associated with the supplied post ID, if it's available
23 * and marked as being available for public display. The returned array will contain
24 * "latitude", "longitude" and "label" keys.
25 *
26 * If you do not supply a value for $post_id, the global $post will be used, if
27 * available.
28 *
29 * @param integer|null $post_id
30 *
31 * @return array|null
32 */
33 function jetpack_geo_get_data( $post_id = null) {
34 $geo = Jetpack_Geo_Location::init();
35
36 if ( ! $post_id ) {
37 $post_id = $geo->get_post_id();
38 }
39
40 $meta_values = $geo->get_meta_values( $post_id );
41
42 if ( ! $meta_values['is_public'] || ! $meta_values['is_populated'] ) {
43 return null;
44 }
45
46 return array(
47 'latitude' => $meta_values['latitude'],
48 'longitude' => $meta_values['longitude'],
49 'label' => $meta_values['label']
50 );
51 }
52
53 /**
54 * Display the label HTML for the geo-location information associated with the supplied
55 * post ID.
56 *
57 * If you do not supply a value for $post_id, the global $post will be used, if
58 * available.
59 *
60 * @param integer|null $post_id
61 *
62 * @return void
63 */
64 function jetpack_geo_display_location( $post_id = null ) {
65 echo jetpack_geo_get_location( $post_id );
66 }
67
68 /**
69 * Return the label HTML for the geo-location information associated with the supplied
70 * post ID.
71 *
72 * If you do not supply a value for $post_id, the global $post will be used, if
73 * available.
74 *
75 * @param integer|null $post_id
76 *
77 * @return string
78 */
79 function jetpack_geo_get_location( $post_id = null ) {
80 return Jetpack_Geo_Location::init()->get_location_label( $post_id );
81 }
82