Forum Replies Created
-
In reply to: ListMessenger (or PHPlist) integration – plugin?
Thanks Nicola Greco!
I knew there had to be a better solution, something like this, but couldn’t put it together.
So I replaced that database line with this:
$uid = get_userdata($user_id);
$email = $uid->user_email;Works fine.
In reply to: Only show required fields on signup formI can live with in this case, but let us know if you have a better solution.
In reply to: Import existing userJeff Sayre, I already google a lot of things. I don’t think it’s off-topic to point out that this essential Buddypress plugin – that should be a built-in BP feature… – runs into this time-out when you use it with over 490 users.
All my issues may be very boring, annoying and off-topic to you, but I’m just a regular web developer (html, css, a bit of js and php) running into lots of basic issues that aren’t solved. I had no intention learning PHP, but Buddypress has lots of loose ends.
I hope by posting here the programmers at Automattic become aware of issues and that other developers on this forum can benefit from solutions I or others come up with.
In reply to: Import existing userTrying to use Manoj Kumar’s Buddypress Users Import plugin. I get this error:
Fatal error: Maximum execution time of 30 seconds exceeded in /serverpath/wp-includes/class-phpass.php on line 60
I don’t recognize anything in that line:
function get_random_bytes($count)
{
$output = '';
if (($fh = @fopen('/dev/urandom', 'rb'))) {
$output = fread($fh, $count);
fclose($fh);
}Can I just temporarily delete it? Would that solve the problem? Other solutions?
I’m trying to import 600+ members, so I’m not surprised it times out.
EDIT: 490 members were actually imported quite nicely!

EDIT2: Not as nicely as I first thought… Username and full name didn’t make it over, only email addresses. Should I have added labels to the top line?
EDIT3: There is no fast way to delete 490 users…?
EDIT4: Does this plugin also update firstname + username in wp_usermeta. If not, I have to add it.
In reply to: Only show required fields on signup formThanks r-a-y!
I like jQuery. I already use it for several other things, so this looks like a good solution.
I hope a more built-in solution will be added to coming versions of Buddypress.
In reply to: Show xprofile data?Thanks Treblamah!
Wow, that is horribly unusable again…

This spits out all the xprofile data:
<?php bp_get_profile_header() ?>
<?php bp_the_avatar() ?>
<?php if ( function_exists('xprofile_get_profile') ) : ?>
<?php xprofile_get_profile() ?>
<?php else : ?>
<?php bp_core_get_wp_profile() ?>
<?php endif; ?>And I guess I have to add parameters to make it more selective. Or copy that xprofile_get_profile function and customize it.
I’ll look into that later…
In reply to: ListMessenger (or PHPlist) integration – plugin?This works:
function synchro_mailinglist($user_id, $password, $meta) {
global $bp, $wpdb;
$email = $wpdb->get_var("SELECT user_email FROM $wpdb->users WHERE ID='$user_id'");
$fullname = $meta[field_1];
$space = strpos( $fullname, ' ' );
$company = $meta[field_2];
if ( false === $space ) {
$firstname = $fullname;
$lastname = '';
} else {
$firstname = substr( $fullname, 0, $space );
$lastname = trim( substr( $fullname, $space, strlen($fullname) ) );
}
$firstname = nameize($firstname);
$lastname = nameize($lastname);
...
$wpdb->query("INSERT mailingusers SET users_id='$user_id', group_id='1', signup_date= UNIX_TIMESTAMP(), firstname= '$firstname', lastname= '$lastname', email_address = '$email' ");
$wpdb->query("INSERT mailingcdata SET cdata_id=NULL, user_id='$user_id', cfield_id='1', value='$company'");
}
add_action( 'wpmu_activate_user', 'synchro_mailinglist', 10, 3);I used it as part of this function. This should work other mailinglist scripts as well, just change the table and field names.
I don’t understand why $user_email didn’t work. I had to pull the user_email from the database. Is there a cleaner way?
In reply to: ListMessenger (or PHPlist) integration – plugin?Even this doesn’t work:
$email = $wpdb->query("SELECT user_email FROM $wpdb->signups WHERE activation_key = %s", $key);And this also does not work:
$email = $wpdb->query("SELECT user_email FROM $wpdb->users WHERE ID = %s", $user_id);??
In reply to: ListMessenger (or PHPlist) integration – plugin?I’m now trying to add firstname, lastname and email address straight to the database tables of my mailing list. I’ve added the queries to the function I had put together here:
function synchro_wp_usermeta($user_id, $password, $meta) {
global $bp, $wpdb;
...
$wpdb->query("INSERT mailingusers SET users_id='$user_id', group_id='1', signup_date= UNIX_TIMESTAMP(), firstname= '$firstname', lastname= '$lastname', email_address= '$user_email'");
$wpdb->query("INSERT mailingcdata SET cdata_id=NULL, user_id='$user_id', cfield_id='1', value='$company'");
}
add_action( 'wpmu_activate_user', 'synchro_wp_usermeta', 10, 3);This mostly works, except the for the email address. $firstname, $lastname and $user_id are all correctly added to the table, but the email_address field stays empty.
Can anyone spot the problem?
How can I “call” the user’s email address upon ‘wpmu_activate_user’?
Adding a $user_email argument only produces missing argument errors. I’m out of guesses…
$current_user->user_email doesn’t work either:
$wpdb->query("INSERT mailingusers SET users_id='$user_id', group_id='1', signup_date= UNIX_TIMESTAMP(), firstname= '$firstname', lastname= '$lastname', email_address= '$current_user->user_email'");Styling the signup form is supposed to become a lot easier in the upcoming version 1.1.
To get my signup form somewhat in line with the rest of the site I had to hack core files. Details of my attempts here.
I’d like to test this plugin as well.
In reply to: Securing components from non logged in usersI think there was one } missing in Enlightenmental1’s latest version:
<?
function js_restrict_access(){
global $bp, $bp_unfiltered_uri;
if (!is_user_logged_in() &&
(BP_MEMBERS_SLUG == $bp_unfiltered_uri[0] ||
BP_GROUPS_SLUG == $bp->current_component ||
BP_BLOGS_SLUG == $bp->current_component)){
bp_core_redirect( get_option('home') . "/register" );
}
}
add_action( 'wp', 'js_restrict_access', 3 );
?>How can I make this work for a custom page/component? How is BP_GROUPS_SLUG etc. defined?
I’ve tried adding this to the top of my custom page, but that did not do the trick:
/* Define the slug for the component */
if ( !defined( 'BP_EVENTS_SLUG' ) )
define ( 'BP_EVENTS_SLUG', 'events' );This doesn’t work either:
if (!is_user_logged_in() &&
(BP_MEMBERS_SLUG == $bp_unfiltered_uri[0] ||
BP_GROUPS_SLUG == $bp->current_component ||
BP_BLOGS_SLUG == $bp->current_component ||
get_option('home').'/events' == $bp->current_component)){
...In reply to: Use full name in confirmation emailsThis works!:
$welcome_email = str_replace("DISPLAYNAME", $meta[field_1], $welcome_email );In reply to: control of new user activation emailI meant to say, no, it’s NOT possible. Not without some serious hacking.
In reply to: Activation/signup email text in Buddypress?What is now the recommended approach for editing the activation/signup emails?
Other threads about this:
Modified mail message registration
In reply to: Clean professional user registration?The html of the custom xprofile fields is generated by yet another function; get_edit_html() in bp-xprofile-classes.php. So if you want to change anything in the custom fields, including the * for required fields, you’ll need to copy/rename that function to bp-custom.php as well.
EDIT: …which is not straightforward:
Fatal error: Call to undefined method BP_XProfile_Field::custom_get_edit_html() in /serverpath/wp-content/mu-plugins/bp-custom.php on line 256
In reply to: Autogenerate or remove usernameTo autogenerate a temporary username put this function in bp-custom.php:
function randomusername() {
$length = 10; //length of string
$start = 65; //Where to start from on ascii table
$end = 90; //where to end on the table
for ($k = 0; $k < $length; $k++){
$randomname .= strtolower(chr(round(rand($start, $end))));
}
return $randomname;
}Make this edit to the username input field on the form (hacking core file, should become easier in version 1.1):
<input name="user_name" type="text" id="user_name" value="'.$user_name = randomusername().'" maxlength="50" />Test it if you want; you’ll see a random string in the username field that will be replace by the autogenerated username based on fullname on activation.
You can hide the username field on the signup form, without getting error messages for not giving it proper TLC, by using this CSS trick.
That requires another core file hack, since you need to add a id like username-form-field. Again, should become easier in version 1.1.
My registration form is now:
Name:
Email address:
And that’s it! Everything works. Full name is available as first and/or last name. The URL is the full name lower case without spaces.

Only thing left to do is clean up the email messages etc. that still mention the username…
In reply to: Autogenerate or remove usernameIf so, the display name is still editable via the “Edit Profile” screen (like I stated above). Not sure what would happen if you attempted to change the display name… would it sync up with the usermeta table?
Yes it does, that’s what the original xprofile_sync_wp_profile() already did, although I think you can turn it off in the admin area. Even if you did that, it wouldn’t mess up anything vital.
My main concern was to consistently get a separate first name + last name in the database, because I need them for several other scripts. That only needs to happen on activation.
Also I needed to learn how to use the fullname value in a function so I could autogenerate a username from it.
Re: rearranging the signup page… BP 1.1 will enable you to move fields around on the sign up page. Check out testbp.org as an example of a customized register page.
I need my site done before Labor Day or September 1st really. And the new more versatile template system does not solve any of my other issues.
In reply to: Clean professional user registration?Temporary solution how to customize registration form until 1.1 arrives, FYI and my own reference:
Changed this line in function bp_show_register_page() in functions.php in my template:
require ( BP_PLUGIN_DIR . '/bp-core/bp-core-signup.php' );to
require ( 'custom-signup.php' );Copied bp-core-signup.php to the template folder, renamed to custom-signup.php.
Go customize!

Unfortunately the custom fields are generated by yet another core function:
do_action( 'signup_extra_fields', $errors );This action is associated with the function xprofile_add_signup_fields in bp-xprofile/bp-xprofile-signup.php.
Copied the function to bp-custom.php, renamed action and function to custom_signup_extra_fields and custom_xprofile_add_signup_fields.
Used this CSS trick to hide the avatar upload. Will use the same trick to hide the username field.
In reply to: Autogenerate or remove usernameThanks for the suggestion r-a-y.
The autogenerated username should behave pretty much as the normal username; it shouldn’t be possible to change the username. The URL to the profile page should stay the same, even if the user decides to change his name – which would be a bit unusual anyway.
Or am I missing some other consequences…?
Next problem to solve is what to do with the username field on the registration form. It should get an autogenerated temporary value, to be replaced by the function on activation, and be hidden from the user. I found this code to generate a random string:
$len = 16;
$base='ABCDEFGHKLMNOPQRSTWXYZabcdefghjkmnpqrstwxyz123456789';
$max=strlen($base)-1;
$activatecode='';
mt_srand((double)microtime()*1000000);
while (strlen($activatecode)<$len+1)
$activatecode.=$base{mt_rand(0,$max)};
echo $activatecode;To add that as value on the registration form I probably have to hack core file. Moving my attention to rearranging the signup form next…
In reply to: Autogenerate or remove usernameThis basically works!:
function synchro_wp_usermeta($user_id, $password, $meta) {
global $bp, $wpdb;
$fullname = $meta[field_1];
$space = strpos( $fullname, ' ' );
if ( false === $space ) {
$firstname = $fullname;
$lastname = '';
} else {
$firstname = substr( $fullname, 0, $space );
$lastname = trim( substr( $fullname, $space, strlen($fullname) ) );
}
$lowercase = strtolower($fullname);
$autousername = str_replace(' ', '', $lowercase);
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 user_login = %s WHERE ID = %d", $autousername, $user_id ) );
$wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->users} SET user_nicename = %s WHERE ID = %d", $autousername, $user_id ) );
$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 ) );
}
add_action( 'wpmu_activate_user', 'synchro_wp_usermeta', 10, 3);All the usernames in the database get updated to the new username autogenerated from fullname! Even the URL takes the new username.
Except the user_login in wp_signups. The signups table doesn’t have a user ID. I’ve tried adding an argument $user_email and this line:
$wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->signups} SET user_login = %s WHERE user_email = %d", $autousername, $user_email ) );But I get a missing argument error and all the entire column of user_logins is reset to the autousername of the latest user. Apparently ‘WHERE user_email = %d’ doesn’t work.
I’m not sure if I should waste much time on this. Is the user_login in wp_signups used anywhere? It appears in the emails, but those have to be rewritten anyway for email login.
In reply to: Autogenerate or remove usernameForget the previous post for now. I’m now assuming $user_id is in fact an ID number. So something like this should cover the two most important of the four usernames in the database:
function synchro_wp_usermeta($user_id, $password, $meta) {
global $bp, $wpdb;
$fullname = $meta[field_1];
$space = strpos( $fullname, ' ' );
if ( false === $space ) {
$firstname = $fullname;
$lastname = '';
} else {
$firstname = substr( $fullname, 0, $space );
$lastname = trim( substr( $fullname, $space, strlen($fullname) ) );
}
$lowercase = strtolower($fullname);
$autousername = str_replace(' ', '', $lowercase);
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 user_login = %s WHERE ID = %d", $autousername, $user_id ) );
$wpdb->query( $wpdb->prepare( "UPDATE {$wpdb->users} SET user_nicename = %s WHERE ID = %d", $autousername, $user_id ) );
$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 ) );
}
add_action( 'wpmu_activate_user', 'synchro_wp_usermeta', 10, 3);I’ll try that and look into the bp_core_get_user_domain() function after lunch…
In reply to: Autogenerate or remove usernameThis function for bp-custom.php adds fullname from xprofile field_1 to wp_usermeta.
function synchro_wp_usermeta($user_id, $password, $meta) {
global $bp, $wpdb;
$fullname = $meta[field_1];
$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 ) );
}
add_action( 'wpmu_activate_user', 'synchro_wp_usermeta', 10, 3);It shouldn’t be a big step to make the fullname lowercase, strip the spaces and store it as username.
Make lowercase and strip space looks something like this:
$str = strtolower($str);
$str = str_replace(' ', '', $str);But does the system even allow changing the username at the wpmu_activate_user stage?
The username is stored in four places in the database:
wp_signups -> user_login
wp_users -> user_login
wp_users -> user_nicename (?!)
wp_users -> user_url (as last part)
Manually changing the username at these points in the database does NOT screw up my system. Login with email address continues to work fine with the same password. The profile page and links function as normal.

That is good news. It means it is possible to simply update the username from this same function.
Now I just have to figure out the PHP and the queries for those four fields. Any pointers apprecriated!
EDIT: Is $user_id a number or the username? That could complicate things…
I assume $user_id is the username. Can I make this a two-stage rocket? First run the synchro_wp_usermeta function and then a separate function to deal with username, synchro_name_username? Put them in a plugin with something like this at the bottom?:
add_action( 'wpmu_activate_user', 'synchro_wp_usermeta', 10, 3);
add_action( 'wpmu_activate_user', 'synchro_name_username');Would that execute the functions in the right order?
So how about this then, following DJPaul’s suggestions:
function synchro_wp_usermeta($user_id, $password, $meta) {
global $bp, $wpdb;
$fullname = $meta[field_1];
$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 ) );
}
add_action( 'wpmu_activate_user', 'synchro_wp_usermeta', 10, 3);Can I simply replace $bp->loggedin_user->id with $user_id?
Trying now…
IT WORKS!!! HALLELUJA!!!
Thanks DJPaul for all the essential clues!
This is the function that the regular wpmu registration process uses to add the user to wp_usermeta:
function update_usermeta( $user_id, $meta_key, $meta_value ) {
global $wpdb;
if ( !is_numeric( $user_id ) )
return false;
$meta_key = preg_replace('|[^a-z0-9_]|i', '', $meta_key);
/** @todo Might need fix because usermeta data is assumed to be already escaped */
if ( is_string($meta_value) )
$meta_value = stripslashes($meta_value);
$meta_value = maybe_serialize($meta_value);
if (empty($meta_value)) {
return delete_usermeta($user_id, $meta_key);
}
$cur = $wpdb->get_row( $wpdb->prepare("SELECT * FROM $wpdb->usermeta WHERE user_id = %d AND meta_key = %s", $user_id, $meta_key) );
if ( !$cur )
$wpdb->insert($wpdb->usermeta, compact('user_id', 'meta_key', 'meta_value') );
else if ( $cur->meta_value != $meta_value )
$wpdb->update($wpdb->usermeta, compact('meta_value'), compact('user_id', 'meta_key') );
else
return false;
wp_cache_delete($user_id, 'users');
return true;
}Is this function also used by Buddypress or does Buddypress replace it with something else?
Where do meta_key and meta_value come from? Data from Buddypress xprofile field_1 is not included at this point…
What would happen if I just added $bp as global? Trying that now… EDIT: Does nothing.
I see xprofile_sync_wp_profile() uses this same function….