Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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_get_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 remove_unwanted_locations($locations){
$allowed_locations = array(
'accounts/108315001685516702892/locations/5619485337829278148',
'accounts/106802586615212834224/locations/1164615868280560907'
);
foreach($locations->locations as $key => $location){
if(!in_array($location->name, $allowed_locations)){
unset($locations->locations[$key]);
}
}
return $locations;
}
add_filter('mbp_get_locations', 'remove_unwanted_locations');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment