yes, but get_userdata() doesn’t return values like avatar and additional profile fields from registration. I found some functions in a core but I am not sure I should go that deep to get this info.
bp_core_get_userurl()
bp_core_get_avatar()
bp_core_get_userlink()
and finaly the best one:
xprofile_get_field_data()
You could use BuddyPress’ x-profile fields to create a required, custom radio button for gender.
The hard part will be hacking the activity feed to show the pronoun differential.
You’d have to create your own function similar to Buddypress’ bp_your_or_their() function.
Then apply that function as a filter on bp_activity_content_filter.
Hi,
I have wpmu 2.8.2 & buddypress 1.0.3. I set up some required profile fields which appears during registration, but does not get saved into the buddypress xprofile table.
Any idea why
Thanks
Manoj
I’m not sure what you want to do, but with this code, you can get a list of the options and the amount of users who have selected the option. Note: for selectbox and radio fields only.
$field_id = 1; // this should be the id of the
// field you want, see your wp_bp_xprofile_fields
// database table to find it
global $wpdb;
$sql = "SELECT value FROM {$wpdb->base_prefix}bp_xprofile_data WHERE field_id = {$field_id} ORDER BY id DESC";
$result = $wpdb->get_col($wpdb->prepare($sql));
foreach($result as $row){
if(strlen($row) > 0){
$values[$row]++;
}
}
$i = 0;
foreach($values as $key => $value){
$i++;
if($i != 1){
echo ", ";
}
echo $key . "(" . $value . ")";
}
Ahh okay… forget my last post entirely then! haha.
Not sure if this will work at all…
$myxprofileFields = new BP_XProfile_ProfileData::get_value_byfieldname('Hair Color');
echo $myxprofileFields();
This is where my knowledge of PHP stops here!
I’m not that great with classes and objects.
Hey Chris,
I’m assuming you’re using one of the prebuilt fields called “State”.
I didn’t look too closely at the classes or template tags, but check out /buddypress/bp-xprofile/bp-xprofile-classes.php.
There’s a function called “get_prebuilt_field_data()” that might help you out there.
You’d have to pass the CSV file to that function, but that might help…
Another way to output the “State” data would be to parse the actual CSV itself that is used for the data. The CSV can be found in buddypress/bp-xprofile/prebuilt-fields/states.csv.
Hope that helps somewhat!
In my first stunt ever as a “real” WordPress/BuddyPress plugin developer, I’ve hacked together a simple stats plugin.
It generates the following graphs:
- (all “multiselectbox”, “selectbox”, “checkbox” and “radio” fields have one bar graph each) (Xprofile)
- Most friends (Friends)
- Most group members (Groups)
- Most actions (Activity)
- Most popular component_action (Activity)
It is available in the WordPress plugin directory. Please try it out and come with suggestions for improvement!
This plugin attempt doesn’t break anything, but still doesn’t put first_name and last_name in wp_usermeta either:
`
<?php
/*
Plugin Name: Real Name Synchro
Plugin URI: http://
Version: v0.001
Author: peterverkooijen
Description: A plugin to store firstname and lastname from the fullname field in Buddypress registration in WPMU usermeta tables.
*/
function real_name_synchro() {
global $bp, $wpdb, $bp_user_signup_meta;
$fields = BP_XProfile_Field::get_signup_fields();
if ( $fields ) {
foreach ( $fields as $field ) {
$value = $_POST[‘field_’ . $field->id];
}
}
$field->id = ‘1’;
$fullname = $value;
$space = strpos( $fullname, ‘ ‘ );
if ( false === $space ) {
$firstname = $fullname;
$lastname = ”;
} else {
$firstname = substr( $fullname, 0, $space );
$lastname = trim( substr( $fullname, $space, strlen($fullname) ) );
}
update_usermeta( $user_id, ‘nickname’, $fullname );
update_usermeta( $user_id, ‘first_name’, $firstname );
update_usermeta( $user_id, ‘last_name’, $lastname );
$wpdb->query( $wpdb->prepare( “UPDATE {$wpdb->users} SET display_name = %s WHERE ID = %d”, $fullname, $user_id ) );
$wpdb->query( $wpdb->prepare( “UPDATE {$wpdb->users} SET user_url = %s WHERE ID = %d”, bp_core_get_user_domain( $user_id ), $user_id ) );
}
//Actions
add_action(‘user_register’, ‘real_name_synchro’);
//Filters
?>`
Can anyone suggest fixes or am I fundamentally on the wrong track?
I want to consistently run function xprofile_sync_wp_profile() during registration.
As it is the function takes fullname data from the database when the user is logged in, so it can not be run during registration.
For a plugin that does what I need I’d have to take the fullname name value straight from the registration form, so I would have to change this line in the xprofile_sync_wp_profile() function:
$fullname = xprofile_get_field_data( BP_XPROFILE_FULLNAME_FIELD_NAME, $bp->loggedin_user->id );
What should I put after = to get the fullname value from the form?
I’ve studied the bp-xprofile-signup.php file, but in the code the fullname value is part of an array (?) identified by field_id, which I know is ‘1’ for fullname, but there I get lost, way too complicated php stuff for me. Something like this?!:
$fields = BP_XProfile_Field::get_signup_fields();
if ( $fields ) {
foreach ( $fields as $field ) {
$value = $_POST['field_' . $field->id];
$field->id = '1';
$fullname = $value;
Please help if anyone can. If I can figure this out, I can probably solve several other problems I have been boring you with for the last few months.
Are you using a custom theme? Have you added any required fields via the “BuddyPress > Profile Fields Setup” in WPMU’s backend?
By default, WPMU with BuddyPress installed is setup to do exactly what you are asking–have one “Username” field and one “Name” field on the signup page.
Right now, there doesn’t seem to be a way for a site admin to edit a member’s x-profile information.
Is the feature I’m asking for the same as on the BP 1.1 roadmap?
Xprofile:
* Reorder existing profile fields and profile field groups
* “Profile picture updated” entry on activity streams
* Admin editable profiles for all members
Look at /bp-xprofile/bp-xprofile-signup.php. I’m not writing your code for you, but from the looks of things, I think you need to remove_action() the xprofile_add_signup_fields() call, and add_action your own version of this function, but obviously removing the avatar form field.
Best place for the code would probably be /plugins/bp-custom.php and make your add_action have a priority of 11.
Friendly monday morning bump!
Hi!
All in all my Buddypress installation seems to be running just fine. However I do have one minor problem when new users register for my site.
If they choose not to create a blog at registration everything works great and all the data they entered in the profile fields are saved correctly.
However if they choose to create a blog at registration something goes wrong. All profile fields are dropped and their username is used as their full name. Also, the blog they created will not be attached to their user so it is completely useless.
If they create a blog at a later stage no problems occur.
I am running Buddypress 1.0.2 and WordPress MU 2.7.1.
Can anybody help me fix this – or alternatively tell me how to remove the blog registration option from the signup page, so that users can only register new blogs once they have created and activated a profile?
Thanks in advance!
Mikael
I’m trying to get a handle on just how the data in xprofiles works and how to pull it out for my purpose. Maybe someone can help me on this easy task (and then i can learn to expand this out).
I have 2 fields in xprofiles and simply want to grab that for a given user. Will this function work to do that? If so, where would I store this function in order to make use of the bp_get_field_data function that it relies on. It this is wrong, how should it be change?
function get_user_realName(){
$user[‘First Name’] = bp_get_field_data(‘First Name’, $site_members_template->member->ID);
$user[‘Last Name’] = bp_get_field_data(‘Last Name’, $site_members_template->member->ID);
echo $user[‘First Name’].’ ‘.$user[‘Last Name’];
}
Thanks!
Hi gang,
Just testing the xprofile prebuilt fields under the WPMU admin area – “BuddyPress > Profile Field Setup”.
I added one of the prebuilt profile fields – “Country” (selectbox).
Can somebody see if their Country field is sorted by ascending name when you attempt to edit your profile in your BP install?
—
Mine appears to be all over the place…
Seems to be sorting backwards starting from the Ukraine -> Afghanistan. Then back to alpha order for the UK to Zimbabwe.
—
Is it an issue where BP attempts to import the CSV into the db?
3125432Inactive
I just went through this so I am a voice of experience.
Each additional profile field you add in the profile field setup is added to the xp_bp_xprofile_fields table. By default, there is only one field filled in on the wp_bp_xprofile_data table, which is the “full name.” Once you or someone else begins to add their additional information and hits save, the data table will expand and in a strange albeit normal way. The id of the user, say ‘2’ will be listed repeatedly, as they have multiple pieces of information stored. The id of the table counts sequentially, so you’ll begin to see that number grow exponentially.
Hope that helps.
Brian
To follow up on this, the table you pointed out only has the default field “full name” not any of the custom fields I created. What am I missing?
3125432Inactive
Using WPMU 2.7.1 & bp 1.0.2 w/ only 1 other plugin – admin bar deactivated.
Experienced a 4th Buddypress system crash. Just created a new mysql db and uploaded and reinstalled. I am using aMember membership script to provide folder protection and an integrated plugin for login and data field updates. I suspect all the crashes had to do with the integrated external plugin overwriting the admin field.
All 732 members are listed in the wp-users table as well as the wp_bp_xprofile_data table with the various profile fields.
Issue: Click on Member Directory. First time after db insertion showed a total of 29 members by clicking on each letter of the alphabet. Slowly, after searching for terms, the Member Directory seems to be ‘learning.’ By this I mean that now there are three “z” listings whereas this morning there were none. Now there are six “w” listings whereas this morning there were none. I know from previous installations that there are something like 26 “w” listings.
In previous installations, I seemed to resolve the Member Directory learning curve by switching from Facebuddy to Buddypress default theme. This time I have not installed Facebuddy.
Any ideas? Again, the db shows all the members are there. It’s just the Member Directory does not show them, and even in the lookup, it can’t find them.
Thanks for considering this strange behaviour.
Brian
Well, I found a workaround, but I’m really nervous about unintended consequences. I went into the db and changed “is_required” on the “Name” field from “1” to “0”. Now I can register without the extra profile fields.
It seems that the name field gets set to the username, which is what I need.
Any thoughts about the unintended consequences of this?
Thanks.
I would prefer not to have a separate username and “friendly name” at this point (mainly because I’m using BBPress 0.9.0.5, which only has the one username).
So in my home theme I had removed the ‘signup_extra_fields’ action in functions.php. That is:
remove_action( 'signup_extra_fields', 'xprofile_add_signup_fields' );
It worked fine – the registration page only asked for a username and email address.
In BP 1.02, it no longer works. Entering information on the registration page and pressing next has no effect. It just stays on the registration page.
If I remove the above line from functions.php (and add back the extra fields) everything works fine.
Has my ‘remove_action’ hack been invalidated by changes in 1.02? Is there a better way to ensure that these extra fields don’t appear at signup? Or is the name field now a requirement?
Jeff, fantastic, this works.
Just to make sure I understand *why* it works… by just running the remove_filter() function in bp-custom as I was doing earlier, I guess it was running before the filter was added. What you are doing is delaying the remove_filter() call until all plugins are loaded.
Do I have that right?
Thanks very much.
Hi r-a-y,
Glad the filter is useful to you!
I think the answer to your question is yes, John Smith’s profile would come up in that kind of scenario. The links that are created in BP profiles are merely full-text searches on all BP profiles (this is the link behavior out of the box, and my filters do not change this). Even if the name “Smith” in John’s profile doesn’t link to http://[your-buddypress-url]/members/?s=Smith, that search URL will still be live and accessible from the regular BP search box.
I haven’t looked into the details, but it should be possible to build a plugin that limits search in different ways. You might, for instance, search all profile fields except those that have been tagged as non-searchable (last name, for example). Another strategy: you might only return a hit on (for example) “Smith” if the result appears between anchor tags; in this way, non-linked profile fields would automatically be excluded. The first kind of solution is probably the better one, and I imagine it will be quite easy once field-specific profile search comes along in BP 1.3 https://buddypress.org/about/roadmap/
@Reboot
Okay, thanks to Burt for waking me up enough in IRC to point out my errors, here’s what you need to place in your bp-custom.php file:
<?php
function remove_links(){
remove_filter( 'bp_get_the_profile_field_value', 'xprofile_filter_link_profile_data', 2 );
}
add_action( 'plugins_loaded', 'remove_links' );
?>
That should work.
I’m going to get some sleep now.