Skip to content

Commit

Permalink
Deprecate geo location module (#41193)
Browse files Browse the repository at this point in the history
* Deprecate Jetpack geo location module

* changelog

* Prevent linting error

* Fix linting error

* Update projects/plugins/jetpack/modules/geo-location/class.jetpack-geo-location.php

Co-authored-by: Karen Attfield <karenlattfield@gmail.com>

---------

Co-authored-by: Karen Attfield <karenlattfield@gmail.com>
  • Loading branch information
monsieur-z and coder-karen authored Jan 21, 2025
1 parent a166b07 commit 47714da
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 922 deletions.
5 changes: 1 addition & 4 deletions projects/plugins/jetpack/.phan/baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
// PhanParamTooMany : 40+ occurrences
// PhanPluginDuplicateAdjacentStatement : 40+ occurrences
// PhanTypeMismatchArgumentInternal : 40+ occurrences
// PhanUndeclaredProperty : 40+ occurrences
// PhanTypeExpectedObjectPropAccess : 35+ occurrences
// PhanUndeclaredProperty : 35+ occurrences
// PhanParamSignatureMismatch : 25+ occurrences
// PhanTypeMismatchDefault : 25+ occurrences
// PhanTypeMismatchPropertyProbablyReal : 25+ occurrences
Expand Down Expand Up @@ -320,8 +320,6 @@
'modules/comments/subscription-modal-on-comment/class-jetpack-subscription-modal-on-comment.php' => ['PhanTypeMismatchReturnNullable'],
'modules/copy-post.php' => ['PhanNoopNew'],
'modules/custom-content-types.php' => ['PhanRedefineFunction'],
'modules/geo-location.php' => ['PhanTypeMismatchArgumentNullable'],
'modules/geo-location/class.jetpack-geo-location.php' => ['PhanTypeMismatchArgument'],
'modules/google-fonts/current/class-jetpack-google-font-face.php' => ['PhanUndeclaredFunctionInCallable'],
'modules/google-fonts/current/load-google-fonts.php' => ['PhanNoopNew', 'PhanTypeArraySuspicious', 'PhanTypeMismatchArgumentInternal', 'PhanTypeMismatchReturnProbablyReal'],
'modules/gravatar-hovercards.php' => ['PhanPluginDuplicateConditionalNullCoalescing', 'PhanTypeMismatchArgumentProbablyReal'],
Expand Down Expand Up @@ -506,7 +504,6 @@
'tests/php/json-api/test_class.json-api-platform-jetpack.php' => ['PhanTypeMismatchArgument'],
'tests/php/media/test-class.jetpack-media-extractor.php' => ['PhanTypeMismatchArgument', 'PhanTypeMismatchArgumentProbablyReal'],
'tests/php/media/test-class.jetpack-post-images.php' => ['PhanTypeMismatchArgumentProbablyReal'],
'tests/php/modules/geo-location/test_class.jetpack-geo-location.php' => ['PhanTypeMismatchArgumentProbablyReal'],
'tests/php/modules/photon/test_class.jetpack-photon-static-asset-cdn.php' => ['PhanTypeMismatchProperty'],
'tests/php/modules/post-by-email/test-class.post-by-email-api.php' => ['PhanParamTooMany'],
'tests/php/modules/publicize/test_class.publicize.php' => ['PhanPluginDuplicateConditionalNullCoalescing'],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: other

Deprecate Jetpack geo location module
94 changes: 3 additions & 91 deletions projects/plugins/jetpack/modules/geo-location.php
Original file line number Diff line number Diff line change
@@ -1,97 +1,9 @@
<?php
<?php // phpcs:ignore Squiz.Commenting.FileComment.Missing
/**
* Module: geo-location
* Module Name: Geo Location
* Module Description: Add location data to your posts.
*
* @package automattic/jetpack
*/

/**
* Adds support for geo-location features.
*/

require_once __DIR__ . '/geo-location/class.jetpack-geo-location.php';

/**
* Geo-location shortcode callback for display of location data associated with a post.
*
* Usage with current global $post:
* [geo-location]
*
* Usage with specific post ID:
* [geo-location post=5]
*
* @param array $attributes Shortcode attributes.
*/
function jetpack_geo_shortcode( $attributes ) {
$attributes = shortcode_atts(
array(
'post' => null,
'id' => null,
),
$attributes
);
return jetpack_geo_get_location( $attributes['post'] ? $attributes['post'] : $attributes['id'] );
}
add_shortcode( 'geo-location', 'jetpack_geo_shortcode' );

/**
* Get the geo-location data associated with the supplied post ID, if it's available
* and marked as being available for public display. The returned array will contain
* "latitude", "longitude" and "label" keys.
*
* If you do not supply a value for $post_id, the global $post will be used, if
* available.
*
* @param integer|null $post_id Post ID.
*
* @return array|null
*/
function jetpack_geo_get_data( $post_id = null ) {
$geo = Jetpack_Geo_Location::init();

if ( ! $post_id ) {
$post_id = $geo->get_post_id();
}

$meta_values = $geo->get_meta_values( $post_id );

if ( ! $meta_values['is_public'] || ! $meta_values['is_populated'] ) {
return null;
}

return array(
'latitude' => $meta_values['latitude'],
'longitude' => $meta_values['longitude'],
'label' => $meta_values['label'],
);
}

/**
* Display the label HTML for the geo-location information associated with the supplied
* post ID.
*
* If you do not supply a value for $post_id, the global $post will be used, if
* available.
*
* @param integer|null $post_id Post ID.
*
* @return void
*/
function jetpack_geo_display_location( $post_id = null ) {
echo jetpack_geo_get_location( $post_id ); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped -- Escaped in `Jetpack_Geo_Location::get_location_label`.
}

/**
* Return the label HTML for the geo-location information associated with the supplied
* post ID.
*
* If you do not supply a value for $post_id, the global $post will be used, if
* available.
*
* @param integer|null $post_id Post ID.
*
* @return string
*/
function jetpack_geo_get_location( $post_id = null ) {
return Jetpack_Geo_Location::init()->get_location_label( $post_id );
}
Loading

0 comments on commit 47714da

Please sign in to comment.