本文整理汇总了PHP中xprofile_set_field_data函数的典型用法代码示例。如果您正苦于以下问题:PHP xprofile_set_field_data函数的具体用法?PHP xprofile_set_field_data怎么用?PHP xprofile_set_field_data使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了xprofile_set_field_data函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_exists_when_exists_uncached
/**
* @group exists
*/
public function test_exists_when_exists_uncached()
{
$u = $this->factory->user->create();
$g = $this->factory->xprofile_group->create();
$f = $this->factory->xprofile_field->create(array('field_group_id' => $g));
xprofile_set_field_data($f, $u, 'foo');
$d = new BP_XProfile_ProfileData($f, $u);
wp_cache_delete("{$u}:{$f}", 'bp_xprofile_data');
$this->assertTrue($d->exists());
}
示例2: test_search_users_count
public function test_search_users_count()
{
$u1 = $this->factory->user->create();
$u2 = $this->factory->user->create();
$u3 = $this->factory->user->create();
xprofile_set_field_data(1, $u1, 'Freedom Isn\'t Free');
xprofile_set_field_data(1, $u2, 'Cool Dude');
xprofile_set_field_data(1, $u3, 'Rock And Roll America Yeah');
// Needs a user_id param though it does nothing
$friends = BP_Friends_Friendship::search_users_count('Coo');
$this->assertEquals(1, $friends);
}
示例3: update_profile_fields
/**
* Update xprofile fields from the signup meta data
*
* @param type $user_id
* @param type $signup
*/
public static function update_profile_fields($user_id, $signup)
{
/* Set any profile data */
if (function_exists('xprofile_set_field_data')) {
if (!empty($signup['meta']['profile_field_ids'])) {
$profile_field_ids = explode(',', $signup['meta']['profile_field_ids']);
foreach ($profile_field_ids as $field_id) {
$current_field = $signup['meta']["field_{$field_id}"];
if (!empty($current_field)) {
xprofile_set_field_data($field_id, $user_id, $current_field);
}
}
}
}
}
示例4: post_love_add_love
function post_love_add_love()
{
$lovr = bp_loggedin_user_id();
$love = bp_get_profile_field_data('field=handshake&user_id=' . $lovr);
$otherlove = bp_get_profile_field_data('field=handshake&user_id=' . $_REQUEST['matchid']);
$lovemaking = explode(',', $otherlove);
$lovemaking2 = explode(',', $love);
$lovemaking2[] = $_REQUEST['matchid'];
$love = array_unique($lovemaking2);
$lovemaking3 = implode(',', $love);
xprofile_set_field_data('handshake', $lovr, $lovemaking3);
if (in_array($lovr, $lovemaking)) {
bp_send_harmony_message($lovr, $_REQUEST['matchid']);
}
if (defined('DOING_AJAX') && DOING_AJAX) {
echo $_REQUEST['matchid'];
die;
} else {
wp_redirect(get_permalink($lovr));
exit;
}
}
示例5: xprofile_sync_bp_profile
/**
* Syncs the standard built in NXTClass profile data to XProfile.
*
* @since 1.2.4
* @package BuddyPress Core
*/
function xprofile_sync_bp_profile(&$errors, $update, &$user)
{
global $bp;
if (!empty($bp->site_options['bp-disable-profile-sync']) && (int) $bp->site_options['bp-disable-profile-sync'] || !$update || $errors->get_error_codes()) {
return;
}
xprofile_set_field_data(bp_xprofile_fullname_field_name(), $user->ID, $user->display_name);
}
示例6: add_backcompat
/**
* Create a WP user at signup.
*
* Since BP 2.0, non-multisite configurations have stored signups in
* the same way as Multisite configs traditionally have: in the
* wp_signups table. However, because some plugins may be looking
* directly in the wp_users table for non-activated signups, we
* mirror signups there by creating "phantom" users, mimicking WP's
* default behavior.
*
* @since 2.0.0
*
* @param string $user_login User login string.
* @param string $user_password User password.
* @param string $user_email User email address.
* @param array $usermeta Metadata associated with the signup.
* @return int User id.
*/
public static function add_backcompat($user_login = '', $user_password = '', $user_email = '', $usermeta = array())
{
global $wpdb;
$user_id = wp_insert_user(array('user_login' => $user_login, 'user_pass' => $user_password, 'display_name' => sanitize_title($user_login), 'user_email' => $user_email));
if (is_wp_error($user_id) || empty($user_id)) {
return $user_id;
}
// Update the user status to '2', ie "not activated"
// (0 = active, 1 = spam, 2 = not active).
$wpdb->query($wpdb->prepare("UPDATE {$wpdb->users} SET user_status = 2 WHERE ID = %d", $user_id));
// WordPress creates these options automatically on
// wp_insert_user(), but we delete them so that inactive
// signups don't appear in various user counts.
delete_user_option($user_id, 'capabilities');
delete_user_option($user_id, 'user_level');
// Set any profile data.
if (bp_is_active('xprofile')) {
if (!empty($usermeta['profile_field_ids'])) {
$profile_field_ids = explode(',', $usermeta['profile_field_ids']);
foreach ((array) $profile_field_ids as $field_id) {
if (empty($usermeta["field_{$field_id}"])) {
continue;
}
$current_field = $usermeta["field_{$field_id}"];
xprofile_set_field_data($field_id, $user_id, $current_field);
// Save the visibility level.
$visibility_level = !empty($usermeta['field_' . $field_id . '_visibility']) ? $usermeta['field_' . $field_id . '_visibility'] : 'public';
xprofile_set_field_visibility_level($field_id, $user_id, $visibility_level);
}
}
}
/**
* Filters the user ID for the backcompat functionality.
*
* @since 2.0.0
*
* @param int $user_id User ID being registered.
*/
return apply_filters('bp_core_signups_add_backcompat', $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: google_authorize
function google_authorize()
{
if (!$this->verify()) {
return;
}
if (isset($_GET['code'])) {
//load google class
$google = $this->load_google();
if (isset($_SESSION['google_token'])) {
$gplus_access_token = $_SESSION['google_token'];
} else {
$google_token = $this->google->authenticate();
$_SESSION['google_token'] = $google_token;
$gplus_access_token = $_SESSION['google_token'];
}
//check access token is set or not
if (!empty($gplus_access_token)) {
// capture data
$user_info = $this->googleplus->people->get('me');
$user_email = $this->googleoauth2->userinfo->get();
// to get email
$user_info['email'] = $user_email['email'];
foreach ($this->fields as $key => $value) {
$this->fields[$key] = $user_email[$key];
}
//if user data get successfully
if (isset($user_info['id'])) {
//all data will assign to a session
$_SESSION['google_user_cache'] = $user_info;
$users = get_users(array('meta_key' => $this->google_meta_key, 'meta_value' => $user_info['id'], 'meta_compare' => '='));
if (isset($users[0]->ID) && is_numeric($users[0]->ID)) {
$user_id = $users[0]->ID;
$this->force_login($users[0]->user_email, false);
wp_redirect(site_url());
die;
}
$email = $this->fields['email'];
if (email_exists($email)) {
// user is a member
$user = get_user_by('email', $email);
//print_r($user->ID);
if (is_numeric($user->ID)) {
$this->force_login($this->fields['email'], false);
wp_redirect(site_url());
update_user_meta($user->ID, $this->google_meta_key, $user_info['id']);
die;
}
} else {
// Register this new user
$random_password = wp_generate_password(10, false);
$user_id = wp_create_user($email, $random_password, $email);
update_user_meta($user_id, $this->google_meta_key, $this->fields['id']);
wp_update_user(array('ID' => $user_id, 'user_url' => $this->fields['link'], 'user_nicename' => $this->fields['given_name'], 'display_name' => $this->fields['name']));
if (isset($this->settings['google_map_fields']) && is_array($this->settings['google_map_fields'])) {
if (count($this->settings['google_map_fields']['field'])) {
foreach ($this->settings['google_map_fields']['field'] as $g_key => $g_field) {
xprofile_set_field_data($this->settings['google_map_fields']['bpfield'][$g_key], $user_id, $this->fields[$g_field]);
}
}
}
// Grab Image and set as
$thumb = $user_email['picture'] . '?sz=' . BP_AVATAR_THUMB_WIDTH;
$full = $user_email['picture'] . '?sz=' . BP_AVATAR_FULL_WIDTH;
$this->grab_avatar($thumb, 'thumb', $user_id);
$this->grab_avatar($full, 'full', $user_id);
//Redirect JSON
$this->force_login($this->fields['email'], false);
wp_redirect(home_url());
die;
}
}
}
}
}
示例9: 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);
}
示例10: test_nested
public function test_nested()
{
$this->create_fields(2);
$this->create_users(3);
xprofile_set_field_data($this->fields[0], $this->users[0], 'foo');
xprofile_set_field_data($this->fields[0], $this->users[1], 'bar');
xprofile_set_field_data($this->fields[1], $this->users[2], 'foo');
xprofile_set_field_data($this->fields[1], $this->users[1], 'foo');
$q = new BP_User_Query(array('xprofile_query' => array('relation' => 'OR', array('field' => $this->fields[0], 'compare' => '=', 'value' => 'foo'), array('relation' => 'AND', array('field' => $this->fields[0], 'value' => 'bar'), array('field' => $this->fields[1], 'value' => 'foo')))));
$expected = array($this->users[0], $this->users[1]);
$this->assertEqualSets($expected, array_keys($q->results));
}
示例11: xprofile_sync_bp_profile
/**
* Syncs the standard built in WordPress profile data to XProfile.
*
* @since BuddyPress (1.2.4)
* @package BuddyPress Core
*/
function xprofile_sync_bp_profile(&$errors, $update, &$user)
{
// Bail if profile syncing is disabled
if (bp_disable_profile_sync() || !$update || $errors->get_error_codes()) {
return;
}
xprofile_set_field_data(bp_xprofile_fullname_field_id(), $user->ID, $user->display_name);
}
示例12: bp_core_map_user_registration
/**
* Map a user's WP display name to the XProfile fullname field, if necessary.
*
* This only happens when a user is registered in wp-admin by an administrator;
* during normal registration, XProfile data is provided directly by the user.
*
* @since 1.2.0
*
* @param int $user_id ID of the user.
* @return bool
*/
function bp_core_map_user_registration($user_id)
{
// Only map data when the site admin is adding users, not on registration.
if (!is_admin()) {
return false;
}
// Add the user's fullname to Xprofile.
if (bp_is_active('xprofile')) {
$firstname = bp_get_user_meta($user_id, 'first_name', true);
$lastname = ' ' . bp_get_user_meta($user_id, 'last_name', true);
$name = $firstname . $lastname;
if (empty($name) || ' ' == $name) {
$name = bp_get_user_meta($user_id, 'nickname', true);
}
xprofile_set_field_data(1, $user_id, $name);
}
}
示例13: bp_fetch_user_fullname
function bp_fetch_user_fullname($user_id, $echo = true)
{
global $bp;
if (!$user_id) {
return false;
}
if (!($fullname = wp_cache_get('bp_user_fullname_' . $user_id, 'bp'))) {
if (function_exists('xprofile_install')) {
$fullname = xprofile_get_field_data(BP_XPROFILE_FULLNAME_FIELD_NAME, $user_id);
if (empty($fullname) || !$fullname) {
$ud = get_userdata($user_id);
$fullname = $ud->display_name;
xprofile_set_field_data(BP_XPROFILE_FULLNAME_FIELD_NAME, $user_id, $fullname);
}
} else {
$ud = get_userdata($user_id);
$fullname = $ud->display_name;
}
wp_cache_set('bp_user_fullname_' . $user_id, $fullname, 'bp');
}
if ($echo) {
echo apply_filters('bp_fetch_user_fullname', stripslashes(trim($fullname)));
} else {
return apply_filters('bp_fetch_user_fullname', stripslashes(trim($fullname)));
}
}
示例14: test_bp_user_query_search_wildcards
public function test_bp_user_query_search_wildcards()
{
$u1 = $this->factory->user->create(array('user_login' => 'xfoo'));
xprofile_set_field_data(1, $u1, "Bar");
$q1 = new BP_User_Query(array('search_terms' => 'foo', 'search_wildcard' => 'left'));
$u2 = $this->factory->user->create(array('user_login' => 'foox'));
xprofile_set_field_data(1, $u2, "Bar");
$q2 = new BP_User_Query(array('search_terms' => 'foo', 'search_wildcard' => 'right'));
$u3 = $this->factory->user->create(array('user_login' => 'xfoox'));
xprofile_set_field_data(1, $u3, "Bar");
$q3 = new BP_User_Query(array('search_terms' => 'foo', 'search_wildcard' => 'both'));
$this->assertNotEmpty($q1->results);
$q1 = array_pop($q1->results);
$this->assertEquals($u1, $q1->ID);
$this->assertNotEmpty($q2->results);
$q2 = array_pop($q2->results);
$this->assertEquals($u2, $q2->ID);
$this->assertNotEmpty($q3->results);
foreach ($q3->results as $user) {
$this->assertTrue(in_array($user->ID, array($u1, $u2, $u3)));
}
}
示例15: user_admin_load
/**
* Save the profile fields in Members community profile page.
*
* Loaded before the page is rendered, this function is processing form
* requests.
*
* @since 2.0.0
*
* @param string $doaction Action being run.
* @param int $user_id ID for the user whose profile is being saved.
* @param array $request Request being made.
* @param string $redirect_to Where to redirect user to.
*/
public function user_admin_load($doaction = '', $user_id = 0, $request = array(), $redirect_to = '')
{
// Eventually delete avatar.
if ('delete_avatar' === $doaction) {
check_admin_referer('delete_avatar');
$redirect_to = remove_query_arg('_wpnonce', $redirect_to);
if (bp_core_delete_existing_avatar(array('item_id' => $user_id))) {
$redirect_to = add_query_arg('updated', 'avatar', $redirect_to);
} else {
$redirect_to = add_query_arg('error', 'avatar', $redirect_to);
}
bp_core_redirect($redirect_to);
// Update profile fields.
} elseif (isset($_POST['field_ids'])) {
// Check the nonce.
check_admin_referer('edit-bp-profile_' . $user_id);
// Check we have field ID's.
if (empty($_POST['field_ids'])) {
$redirect_to = add_query_arg('error', '1', $redirect_to);
bp_core_redirect($redirect_to);
}
/**
* Unlike front-end edit-fields screens, the wp-admin/profile
* displays all groups of fields on a single page, so the list of
* field ids is an array gathering for each group of fields a
* distinct comma separated list of ids.
*
* As a result, before using the wp_parse_id_list() function, we
* must ensure that these ids are "merged" into a single comma
* separated list.
*/
$merge_ids = join(',', $_POST['field_ids']);
// Explode the posted field IDs into an array so we know which fields have been submitted.
$posted_field_ids = wp_parse_id_list($merge_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) && !bp_current_user_can('bp_moderate');
if ($is_required[$field_id] && empty($_POST['field_' . $field_id])) {
$redirect_to = add_query_arg('error', '2', $redirect_to);
bp_core_redirect($redirect_to);
}
}
// Set the errors var.
$errors = false;
// Now we've checked for required fields, let's save the values.
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] : '';
if (!xprofile_set_field_data($field_id, $user_id, $value, $is_required[$field_id])) {
$errors = true;
} else {
/**
* Fires after the saving of each profile field, if successful.
*
* @since 1.1.0
*
* @param int $field_id ID of the field being updated.
* @param string $value Value that was saved to the field.
*/
do_action('xprofile_profile_field_data_updated', $field_id, $value);
}
// Save the visibility level.
$visibility_level = !empty($_POST['field_' . $field_id . '_visibility']) ? $_POST['field_' . $field_id . '_visibility'] : 'public';
xprofile_set_field_visibility_level($field_id, $user_id, $visibility_level);
}
/**
* Fires after all of the profile fields have been saved.
*
* @since 1.0.0
*
* @param int $user_id ID of the user whose data is being saved.
* @param array $posted_field_ids IDs of the fields that were submitted.
* @param bool $errors Whether or not errors occurred during saving.
*/
do_action('xprofile_updated_profile', $user_id, $posted_field_ids, $errors);
// Set the feedback messages.
//.........这里部分代码省略.........