Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Creating the BuddyPress profile field
<?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
You can’t perform that action at this time.