Last active
February 3, 2020 10:17
-
-
Save 2Fwebd/09283d0373b4e9e5b193f57c291fd826 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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