本文整理汇总了PHP中xprofile_get_field_data函数的典型用法代码示例。如果您正苦于以下问题:PHP xprofile_get_field_data函数的具体用法?PHP xprofile_get_field_data怎么用?PHP xprofile_get_field_data使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了xprofile_get_field_data函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_xprofile_sync_bp_profile_new_user
/**
* @group xprofile_set_field_data
* @ticket BP5836
*/
public function test_xprofile_sync_bp_profile_new_user()
{
$post_vars = $_POST;
$_POST = array('user_login' => 'foobar', 'pass1' => 'password', 'pass2' => 'password', 'role' => 'subscriber', 'email' => 'foo@bar.com', 'first_name' => 'Foo', 'last_name' => 'Bar');
$id = add_user();
$display_name = 'Bar Foo';
$_POST = array('display_name' => $display_name, 'email' => 'foo@bar.com', 'nickname' => 'foobar');
$id = edit_user($id);
// clean up post vars
$_POST = $post_vars;
$this->assertEquals($display_name, xprofile_get_field_data(bp_xprofile_fullname_field_id(), $id));
}
示例2: cfbgr_migrate_xprofile_as_member_types
function cfbgr_migrate_xprofile_as_member_types()
{
global $wpdb;
$buddypress = buddypress();
// Description of this tool, displayed to the user
$statement = __('Migrating/Resetting xProfile data as member types: %s', 'buddypress-group-restrictions');
// Default to failure text
$result = __('No xProfile data needs to be migrated or reset.', 'buddypress-group-restrictions');
// Default to unrepaired
$repair = 0;
$field = (int) bp_get_option('cfbgr_xfield_id', 0);
if (empty($field)) {
return array(0, sprintf($statement, $result));
}
$member_types = bp_get_member_types();
// Walk through all users on the site
$user_ids = $wpdb->get_col("SELECT ID FROM {$wpdb->users}");
foreach ($user_ids as $user_id) {
$value = sanitize_key(xprofile_get_field_data($field, $user_id));
// Do we have a matching member type ?
if (isset($member_types[$value])) {
// Set member types if empty or different
if ($value !== bp_get_member_type($user_id)) {
bp_set_member_type($user_id, $value);
$repair += 1;
}
}
}
$result = sprintf(__('%d migrated or reset', 'buddypress-group-restrictions'), $repair);
// All done!
return array(0, sprintf($statement, $result));
}
示例3: openlab_user_is_admin
function openlab_user_is_admin($is_admin)
{
$account_type = xprofile_get_field_data('Account Type', get_current_user_id());
if ($account_type && 'Faculty' == $account_type) {
$is_admin = true;
}
return $is_admin;
}
示例4: display_user_color_pref
/**
* Adiciona campos no perfil do usuário
*
* @param void
* @return string
*/
function display_user_color_pref()
{
$bp_profissao = xprofile_get_field_data('profissão');
$bp_cidade = xprofile_get_field_data('cidade');
$bp_estado = xprofile_get_field_data('estado');
echo '<p class="field-data">' . $bp_profissao . '</p>';
echo '<p class="field-data">' . $bp_cidade . ' - ' . $bp_estado . '</p>';
}
示例5: rtmedia_api_user_data_from_id
function rtmedia_api_user_data_from_id($user_id, $width = 80, $height = 80, $type = 'thumb')
{
if (empty($user_id)) {
return false;
}
$user_data = array();
$user_data['id'] = $user_id;
$user_data['name'] = xprofile_get_field_data('Name', $user_id);
$avatar_args = array('item_id' => $user_id, 'width' => $width, 'height' => $height, 'html' => false, 'alt' => '', 'type' => $type);
$user_data['avatar'] = bp_core_fetch_avatar($avatar_args);
return $user_data;
}
示例6: xprofile_sync_wp_profile
function xprofile_sync_wp_profile()
{
global $bp, $wpdb;
if ((int) get_site_option('bp-disable-profile-sync')) {
return true;
}
$fullname = xprofile_get_field_data(BP_XPROFILE_FULLNAME_FIELD_NAME, $bp->loggedin_user->id);
$space = strpos($fullname, ' ');
if (false === $space) {
$firstname = $fullname;
$lastname = '';
} else {
$firstname = substr($fullname, 0, $space);
$lastname = trim(substr($fullname, $space, strlen($fullname)));
}
update_usermeta($bp->loggedin_user->id, 'nickname', $fullname);
update_usermeta($bp->loggedin_user->id, 'first_name', $firstname);
update_usermeta($bp->loggedin_user->id, 'last_name', $lastname);
$wpdb->query($wpdb->prepare("UPDATE {$wpdb->users} SET display_name = %s WHERE ID = %d", $fullname, $bp->loggedin_user->id));
$wpdb->query($wpdb->prepare("UPDATE {$wpdb->users} SET user_url = %s WHERE ID = %d", bp_core_get_user_domain($bp->loggedin_user->id), $bp->loggedin_user->id));
}
示例7: xprofile_screen_edit_profile
/**
* Handles the display of the profile edit page by loading the correct template file.
* Also checks to make sure this can only be accessed for the logged in users profile.
*
* @package BuddyPress XProfile
* @uses bp_is_my_profile() Checks to make sure the current user being viewed equals the logged in user
* @uses bp_core_load_template() Looks for and loads a template file within the current member theme (folder/filename)
*/
function xprofile_screen_edit_profile()
{
if (!bp_is_my_profile() && !bp_current_user_can('bp_moderate')) {
return false;
}
$bp = buddypress();
// Make sure a group is set.
if (!bp_action_variable(1)) {
bp_core_redirect(trailingslashit(bp_displayed_user_domain() . $bp->profile->slug . '/edit/group/1'));
}
// Check the field group exists
if (!bp_is_action_variable('group') || !xprofile_get_field_group(bp_action_variable(1))) {
bp_do_404();
return;
}
// No errors
$errors = false;
// Check to see if any new information has been submitted
if (isset($_POST['field_ids'])) {
// Check the nonce
check_admin_referer('bp_xprofile_edit');
// Check we have field ID's
if (empty($_POST['field_ids'])) {
bp_core_redirect(trailingslashit(bp_displayed_user_domain() . $bp->profile->slug . '/edit/group/' . bp_action_variable(1)));
}
// Explode the posted field IDs into an array so we know which
// fields have been submitted
$posted_field_ids = wp_parse_id_list($_POST['field_ids']);
$is_required = array();
// Loop through the posted fields formatting any datebox values
// then validate the field
foreach ((array) $posted_field_ids as $field_id) {
if (!isset($_POST['field_' . $field_id])) {
if (!empty($_POST['field_' . $field_id . '_day']) && !empty($_POST['field_' . $field_id . '_month']) && !empty($_POST['field_' . $field_id . '_year'])) {
// Concatenate the values
$date_value = $_POST['field_' . $field_id . '_day'] . ' ' . $_POST['field_' . $field_id . '_month'] . ' ' . $_POST['field_' . $field_id . '_year'];
// Turn the concatenated value into a timestamp
$_POST['field_' . $field_id] = date('Y-m-d H:i:s', strtotime($date_value));
}
}
$is_required[$field_id] = xprofile_check_is_required_field($field_id);
if ($is_required[$field_id] && empty($_POST['field_' . $field_id])) {
$errors = true;
}
}
// There are errors
if (!empty($errors)) {
bp_core_add_message(__('Please make sure you fill in all required fields in this profile field group before saving.', 'buddypress'), 'error');
// No errors
} else {
// Reset the errors var
$errors = false;
// Now we've checked for required fields, lets save the values.
$old_values = $new_values = array();
foreach ((array) $posted_field_ids as $field_id) {
// Certain types of fields (checkboxes, multiselects) may come through empty. Save them as an empty array so that they don't get overwritten by the default on the next edit.
$value = isset($_POST['field_' . $field_id]) ? $_POST['field_' . $field_id] : '';
$visibility_level = !empty($_POST['field_' . $field_id . '_visibility']) ? $_POST['field_' . $field_id . '_visibility'] : 'public';
// Save the old and new values. They will be
// passed to the filter and used to determine
// whether an activity item should be posted
$old_values[$field_id] = array('value' => xprofile_get_field_data($field_id, bp_displayed_user_id()), 'visibility' => xprofile_get_field_visibility_level($field_id, bp_displayed_user_id()));
// Update the field data and visibility level
xprofile_set_field_visibility_level($field_id, bp_displayed_user_id(), $visibility_level);
$field_updated = xprofile_set_field_data($field_id, bp_displayed_user_id(), $value, $is_required[$field_id]);
$value = xprofile_get_field_data($field_id, bp_displayed_user_id());
$new_values[$field_id] = array('value' => $value, 'visibility' => xprofile_get_field_visibility_level($field_id, bp_displayed_user_id()));
if (!$field_updated) {
$errors = true;
} else {
/**
* Fires on each iteration of an XProfile field being saved with no error.
*
* @since BuddyPress (1.1.0)
*
* @param int $field_id ID of the field that was saved.
* @param string $value Value that was saved to the field.
*/
do_action('xprofile_profile_field_data_updated', $field_id, $value);
}
}
/**
* Fires after all XProfile fields have been saved for the current profile.
*
* @since BuddyPress (1.0.0)
*
* @param int $value Displayed user ID.
* @param array $posted_field_ids Array of field IDs that were edited.
* @param bool $errors Whether or not any errors occurred.
* @param array $old_values Array of original values before updated.
* @param array $new_values Array of newly saved values after update.
*/
//.........这里部分代码省略.........
示例8: bp_core_get_user_displayname
/**
* Fetch the display name for a user. This will use the "Name" field in xprofile if it is installed.
* Otherwise, it will fall back to the normal WP display_name, or user_nicename, depending on what has been set.
*
* @package BuddyPress Core
* @global object $bp Global BuddyPress settings object
* @uses wp_cache_get() Will try and fetch the value from the cache, rather than querying the DB again.
* @uses get_userdata() Fetches the WP userdata for a specific user.
* @uses xprofile_set_field_data() Will update the field data for a user based on field name and user id.
* @uses wp_cache_set() Adds a value to the cache.
* @return str The display name for the user in question.
*/
function bp_core_get_user_displayname($user_id_or_username)
{
global $bp;
$fullname = '';
if (!$user_id_or_username) {
return false;
}
if (!is_numeric($user_id_or_username)) {
$user_id = bp_core_get_userid($user_id_or_username);
} else {
$user_id = $user_id_or_username;
}
if (!$user_id) {
return false;
}
if (!($fullname = wp_cache_get('bp_user_fullname_' . $user_id, 'bp'))) {
if (bp_is_active('xprofile')) {
$fullname = xprofile_get_field_data(stripslashes($bp->site_options['bp-xprofile-fullname-field-name']), $user_id);
if (empty($fullname)) {
$ud = bp_core_get_core_userdata($user_id);
if (!empty($ud->display_name)) {
$fullname = $ud->display_name;
} elseif (!empty($ud->user_nicename)) {
$fullname = $ud->user_nicename;
}
xprofile_set_field_data(1, $user_id, $fullname);
}
} else {
$ud = bp_core_get_core_userdata($user_id);
if (!empty($ud->display_name)) {
$fullname = $ud->display_name;
} elseif (!empty($ud->user_nicename)) {
$fullname = $ud->user_nicename;
}
}
if (!empty($fullname)) {
wp_cache_set('bp_user_fullname_' . $user_id, $fullname, 'bp');
}
}
return apply_filters('bp_core_get_user_displayname', $fullname, $user_id);
}
示例9: get_fullname
public static function get_fullname($user_id = 0)
{
if (empty($user_id)) {
$user_id = bp_displayed_user_id();
}
$data = xprofile_get_field_data(bp_xprofile_fullname_field_id(), $user_id);
return $data[$field_name];
}
示例10: test_bp_core_get_user_displayname_xprofile_does_not_exist
/**
* @group bp_core_get_user_displayname
*/
public function test_bp_core_get_user_displayname_xprofile_does_not_exist()
{
$bp = buddypress();
$xprofile_is_active = bp_is_active('xprofile');
$bp->active_components['xprofile'] = '1';
$u = $this->factory->user->create(array('display_name' => 'Foo Foo'));
// Delete directly because BP won't let you delete a required
// field through the API
global $wpdb;
$wpdb->query($wpdb->prepare("DELETE FROM {$bp->profile->table_name_data} WHERE user_id = %d AND field_id = 1", $u));
wp_cache_delete('bp_user_fullname_' . $u, 'bp');
wp_cache_delete("{$u}:1", 'bp_xprofile_data');
$this->assertSame('', xprofile_get_field_data(1, $u));
$this->assertSame('Foo Foo', bp_core_get_user_displayname($u));
$this->assertSame('Foo Foo', xprofile_get_field_data(1, $u));
if (!$xprofile_is_active) {
unset($bp->active_components['xprofile']);
}
}
示例11: xprofile_sync_wp_profile
/**
* Syncs Xprofile data to the standard built in WordPress profile data.
*
* @since 1.0.0
*
* @param int $user_id ID of the user to sync.
* @return bool
*/
function xprofile_sync_wp_profile($user_id = 0)
{
// Bail if profile syncing is disabled.
if (bp_disable_profile_sync()) {
return true;
}
if (empty($user_id)) {
$user_id = bp_loggedin_user_id();
}
if (empty($user_id)) {
return false;
}
$fullname = xprofile_get_field_data(bp_xprofile_fullname_field_id(), $user_id);
$space = strpos($fullname, ' ');
if (false === $space) {
$firstname = $fullname;
$lastname = '';
} else {
$firstname = substr($fullname, 0, $space);
$lastname = trim(substr($fullname, $space, strlen($fullname)));
}
bp_update_user_meta($user_id, 'nickname', $fullname);
bp_update_user_meta($user_id, 'first_name', $firstname);
bp_update_user_meta($user_id, 'last_name', $lastname);
wp_update_user(array('ID' => $user_id, 'display_name' => $fullname));
wp_cache_delete('bp_core_userdata_' . $user_id, 'bp');
}
示例12: xprofile_sync_nxt_profile
/**
* Syncs Xprofile data to the standard built in NXTClass profile data.
*
* @package BuddyPress Core
*/
function xprofile_sync_nxt_profile($user_id = 0)
{
global $bp, $nxtdb;
if (!empty($bp->site_options['bp-disable-profile-sync']) && (int) $bp->site_options['bp-disable-profile-sync']) {
return true;
}
if (empty($user_id)) {
$user_id = $bp->loggedin_user->id;
}
if (empty($user_id)) {
return false;
}
$fullname = xprofile_get_field_data(bp_xprofile_fullname_field_name(), $user_id);
$space = strpos($fullname, ' ');
if (false === $space) {
$firstname = $fullname;
$lastname = '';
} else {
$firstname = substr($fullname, 0, $space);
$lastname = trim(substr($fullname, $space, strlen($fullname)));
}
update_user_meta($user_id, 'nickname', $fullname);
update_user_meta($user_id, 'first_name', $firstname);
update_user_meta($user_id, 'last_name', $lastname);
$nxtdb->query($nxtdb->prepare("UPDATE {$nxtdb->users} SET display_name = %s WHERE ID = %d", $fullname, $user_id));
}
示例13: bp_get_profile_field_data
/**
* Return XProfile field data.
*
* @since 1.2.0
*
* @param string|array $args {
* Array of arguments for field data.
*
* @type string|int|bool $field Field identifier.
* @type int $user_id ID of the user to get field data for.
* }
* @return mixed|void
*/
function bp_get_profile_field_data($args = '')
{
$r = wp_parse_args($args, array('field' => false, 'user_id' => bp_displayed_user_id()));
/**
* Filters the profile field data.
*
* @since 1.2.0
* @since 2.6.0 Added the `$r` parameter.
*
* @param mixed $value Profile data for a specific field for the user.
* @param array $r Array of parsed arguments.
*/
return apply_filters('bp_get_profile_field_data', xprofile_get_field_data($r['field'], $r['user_id']), $r);
}
示例14: has_student_caps
/**
* has_student_caps( $user_id )
*
* Checks if $user_id has response management capabilities
*
* @param Int $user_id ID of the user capabilities to be checked, default null
* @return True if $user_id is eligible and False if not.
*/
function has_student_caps($user_id = null)
{
global $bp;
if (!$user_id) {
$user_id = $bp->loggedin_user->id;
}
$user_role = xprofile_get_field_data(__('Role'), $user_id);
// Go away teacher
if (__('Student', 'bpsp') != $user_role && !empty($user_role)) {
return false;
}
// Treat super admins
if (is_super_admin($user_id)) {
$this->add_response_caps($user_id);
}
$user = new WP_User($user_id);
foreach ($this->students_caps as $c) {
if (!$user->has_cap($c)) {
$user->add_cap($c);
}
}
return true;
}
示例15: rw_boss_social_header
function rw_boss_social_header()
{
?>
<div class="btn-group social">
<?php
foreach (rw_boss_get_user_social_array() as $social => $arr) {
$url = xprofile_get_field_data($social, bp_displayed_user_id(), 'comma');
$ico = empty($arr['icon-url']) ? '<i class="alt-social-icon alt-' . $social . '"></i>' : '<img class="user-social-icons-btn" src="' . $arr['icon-url'] . '">';
if (!empty($url)) {
?>
<a class="btn" href="<?php
echo $url;
?>
" title="<?php
echo esc_attr($arr['title']);
?>
"><?php
echo $ico;
?>
</a>
<?php
}
?>
<?php
}
?>
</div>
<?php
}