Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?php
/**
* Load the BuddyPress members coordinates
*
* This is an Ajax callback, we just output the locations as a formatted JSON array
*
* @return void
*/
public function loadMembers() {
$is_request_safe = (
wp_verify_nonce($_POST['_nonce'], 'woffice_map_members')
&&
is_admin()
&&
defined('DOING_AJAX')
&&
DOING_AJAX
);
if ($is_request_safe === false) {
wp_die();
}
// Get our saved data
$saved_locations = get_option('woffice_map_locations');
if (empty($saved_locations) || $saved_locations == '[]') {
$saved_locations = '[{"name":"No Data","lat":0,"long":0,"user_id":1}]';
}
$locations = (array) json_decode($saved_locations, true);
// Add any extra information here
foreach($locations as $key=>$location) {
$locations[$key]['avatar'] = get_avatar($location['user_id']);
}
/**
* Filter `woffice_members_map_locations`
*
* Gives the ability to customize the Members locations array before it's being returned
*
* @return array
*/
$locations = apply_filters('woffice_members_map_locations', $locations);
// Return the value & end
echo json_encode($locations);
wp_die();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.