Skip to content

Instantly share code, notes, and snippets.

@koen12344
Last active June 29, 2022 08:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koen12344/b510297fe7ac2e074848a67c319e2be5 to your computer and use it in GitHub Desktop.
Save koen12344/b510297fe7ac2e074848a67c319e2be5 to your computer and use it in GitHub Desktop.
Hide specific locations from users in Post to GMB plugin
<?php
/*
It is possible to limit the location list to specific locations (or a single location) using the mbp_business_selector_locations filter.
We can use it to filter out the locations that don't belong to the website or user.
The code loops through all locations and checks whether the location is within an array of allowed locations. If not, it is removed (hidden).
You can find the location ID by right clicking the location in the location selector, and pressing "Inspect Element": https://i.imgur.com/gWd5M9x.png
*/
function pgmb_remove_unwanted_locations($locations){
$allowed_locations = array(
'locations/11175850243276969608',
'locations/1164615864330560907'
);
foreach($locations as $key => $location){
if(!in_array($location->name, $allowed_locations)){
unset($locations[$key]);
}
}
return $locations;
}
add_filter('mbp_business_selector_locations', 'pgmb_remove_unwanted_locations');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment