Created
February 2, 2019 19:13
-
-
Save 2Fwebd/5e75d6bb81f80277eb6cb4af1018d10c to your computer and use it in GitHub Desktop.
Creating the BuddyPress profile field
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 | |
/** | |
* Class Woffice_Members_Map | |
* | |
* This class handles the Members Map backend actions and callbacks. | |
* | |
* As well as the render part | |
* | |
*/ | |
class Woffice_Members_Map | |
{ | |
/** | |
* Our BuddyPress Xprofile Field name | |
* | |
* @var string | |
*/ | |
private $fieldName = 'Location'; | |
/** | |
* Woffice_Members_Map constructor. | |
* | |
* | |
*/ | |
public function __construct() | |
{ | |
// We only run this class if BuddyPress is enabled and so is the xProfile component | |
if (!function_exists('bp_is_active') || !bp_is_active('xprofile')) { | |
return; | |
} | |
// WordPress Actions | |
add_action('xprofile_updated_profile', array($this, 'createProfileField')); | |
} | |
/** | |
* This function creates the BuddyPress Xprofile field | |
* | |
* It's hooked to the `xprofile_updated_profile` action, so it will be called on every profile update. | |
*/ | |
public function createProfileField() | |
{ | |
global $wpdb; | |
// We look for an existing field | |
$sql = 'SELECT `id`, `type` FROM '. $wpdb->prefix .'bp_xprofile_fields WHERE `name` = "'. $this->fieldName .'"'; | |
$field = $wpdb->get_results($sql); | |
// We do not recreate it | |
if (count($field) > 0) { | |
return; | |
} | |
xprofile_insert_field( | |
array ( | |
'field_group_id' => 1, | |
'can_delete' => true, | |
'type' => 'textbox', | |
'description' => __('This address will be used on the members directory map, please make sure this address is valid for Google Map.','woffice'), | |
'name' => $this->fieldName, | |
'field_order' => 1, | |
'is_required' => false, | |
) | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment