Skip to:
Content
Pages
Categories
Search
Top
Bottom

Forum Replies Created

Viewing 25 replies - 501 through 525 (of 690 total)
  • @peterverkooijen

    Participant

    @Mike Pratt, I’ve tried the honey approach in the past. I’m not even counting on responses anymore. I post my attempts here to keep track of what I’m doing and hopefully in the end the thread becomes useful for others in my situation.

    @DJPaul, thanks for the additional clue. I think I need to go back to that “flowchart of registration events in wpmu” and get a better insight what happens where in the process.

    @peterverkooijen

    Participant

    Thanks for the additional info Jeff Sayre! Now at least I know I’m not wasting my time. ;-)

    @peterverkooijen

    Participant

    BTW, how will fullname/firstname+lastname be handled in the new version? Will it be synchronized with wp_usermeta? Or will there be built-in fields in xprofile? Or another solution?

    Will there be an option to make them required? Will you offer an option to autogenerate username from fullname?

    Trying to decide which way to go for temporary solutions.

    @peterverkooijen

    Participant

    How can you identify the user on wpmu_activate_user? Only by the key from the activation link? How does that work?

    Then $bp->loggedin_user->id doesn’t work on activation either, does it?

    How is Lance Willet able to use $userid on wpmu_activate_user?

    Can I somehow use that to pull up the right meta row from wp_signups and store the values in wp_usermeta with the right user_id?

    Or can I use the email address as an identifier?

    @peterverkooijen

    Participant

    This should work:

    function synchro_wp_usermeta( $user_id, $password, $meta ) {
    global $bp, $wpdb;

    $fullname = $meta[field_1];

    echo $fullname;

    $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 ) );
    }
    add_action( 'wpmu_activate_user', 'synchro_wp_usermeta', 10, 3);

    BTW, I see Lance Willet here uses $userid with wpmu_activate_user, instead of $key.

    Does $bp->loggedin_user->id even work on activation? Shouldn’t everything be based on the activation key?

    @peterverkooijen

    Participant

    This works!

    $array = $wpdb->get_var("SELECT meta FROM $wpdb->signups");

    $my_vars = unserialize($array);

    $fullname = $my_vars[field_1];

    echo $fullname;

    I know it’s basically DJPaul’s solution, twenty posts back, but minus the apostrophes.

    So now I know how to get the fullname, but still not how to get the fullname of the user that is activating = has the activation key?

    Why doesn’t this work then?:

    function synchro_wp_usermeta($key) {
    global $bp, $wpdb;

    $array = $wpdb->get_var("SELECT meta FROM $wpdb->signups WHERE activation_key = %s", $key);

    $my_vars = unserialize($array);

    $fullname = $my_vars[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( $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 ) );
    }
    add_action( 'wpmu_activate_user', 'synchro_wp_usermeta', 10, 1);

    @peterverkooijen

    Participant

    With this:

    $array = $wpdb->get_var("SELECT meta FROM $wpdb->signups");
    $my_vars = unserialize($array);

    foreach($my_vars as $name => $value)
    {
    print $name . ' has the value: ' . $value . '<br />';
    }

    I get this:

    field_1 has the value: Julius Caesar

    xprofile_field_ids has the value: 1,

    avatar_image_resized has the value: /serverpath/wp-content/blogs.dir/1/files/avatars/0/caesar.jpg

    avatar_image_original has the value: /serverpath/wp-content/blogs.dir/1/files/avatars/0/caesar.jpg

    public has the value: 1

    lang_id has the value: 1

    blogname has the value: theempire

    blog_title has the value: The Roman Empire

    So how do I get just that ‘Julius Caesar’ value?

    I’ve tried adding this and many variations. Nothing works:

    $value['field_1'] = $fullname;

    echo $fullname;

    @peterverkooijen

    Participant

    With this I get four missing argument errors again. Why?

    function synchro_wp_usermeta($key, $user_id, $password, $meta) {
    global $bp, $wpdb;

    $fullname = $wpdb->get_var("SELECT meta FROM $wpdb->signups WHERE activation_key = %s", $key);
    echo $fullname;

    $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 ) );
    }
    add_action( 'wpmu_activate_user', 'synchro_wp_usermeta', 10, 4);

    @peterverkooijen

    Participant

    When I do this:

    $fullname = $wpdb->get_var("SELECT meta FROM $wpdb->signups");
    echo $fullname;

    I get the serialized content of the first meta field in wp_signups:

    a:8:{s:7:"field_1";s:13:"Julius Caesar";s:18:"xprofile_field_ids";s:2:"1,";s:20:"avatar_image_resized";s:84:"/serverpath/wp-content/blogs.dir/1/files/avatars/0/caesar.jpg";s:21:"avatar_image_original";s:84:"/serverpath/wp-content/blogs.dir/1/files/avatars/0/caesar.jpg";s:6:"public";s:1:"1";s:7:"lang_id";i:1;s:8:"blogname";s:9:"theempire";s:10:"blog_title";s:16:"The Roman Empire";}

    The function inserted this crap also into the wp_usermeta fields. Success! (Sort of…)

    The bit of data I need is the fullname, the second bit, in this case ‘Julius Caesar’. I’d need the second bit of data from the user with the activation key.

    How would I add that to the query?

    I’ll first try this:

    $fullname = $wpdb->get_var("SELECT meta FROM $wpdb->signups WHERE activation_key = %s", $key);
    echo $fullname;

    Nothing… :-(

    I probably had to add $key as an argument. Trying again after some food…

    In reply to: Paid Member Plugin

    @peterverkooijen

    Participant

    There are several commercial plugins for WordPress. I assume they would work with wpmu and buddypress as well, since those are big potential markets for them.

    @peterverkooijen

    Participant

    Here’s one example.

    You probably have to change $ to jQuery for it to work within WordPress, like this:

    //toggle login block horizontally
    jQuery(".login-toggle").click(function(){
    jQuery("#right-ear-inner").slideFadeToggle("slow");
    jQuery(this).toggleClass("login-toggle-close"); return false;
    });

    More examples and info.

    @peterverkooijen

    Participant

    Probably a jQuery script, perhaps via a plugin, not necessarily. I know there are several WordPress Ajax login plugins.

    I have a similar toggle hide script in my test site, but without the cool jQuery animation effect. They did a very nice job. I should look into that site for “ideas”… ;-)

    @peterverkooijen

    Participant

    Excellent news Jeff Sayre! Any improvement in registration/signup is very welcome.

    I still need to finish my site before Labor Day though…

    @peterverkooijen

    Participant

    In my template functions.php has this function:

    function bp_show_register_page() {
    global $bp, $current_blog;

    require ( BP_PLUGIN_DIR . '/bp-core/bp-core-signup.php' );

    if ( $bp->current_component == BP_REGISTER_SLUG && $bp->current_action == '' ) {
    bp_core_signup_set_headers();
    bp_core_load_template( 'register', true );
    }
    }
    add_action( 'wp', 'bp_show_register_page', 2 );

    I guess I’ll just make a copy of bp-core-signup.php, modify it as needed and change the link in this function. Just redirect the whole process to custom code based on the original BP code.

    Not really a hook, but that would be a way to leave the core code intact.

    I’ll get back to this later this week…

    In reply to: when next release ?

    @peterverkooijen

    Participant

    Removed. Jeff Sayre beat me to it. :-)

    @peterverkooijen

    Participant

    The ideal registration form would look like this:

    – fullname

    – email address

    Both fields would of course be mandatory. Ideally fullname would be checked for two or more parts, but xprofile_sync_wp_profile() can handle one part input and I can live with an occassional missing last name.

    I use a jQuery validation script on another form in my site, that I may also be able to use on the registration form. As far I understand it doesn’t interfere with anything on the server side.

    Username would be generated behind the scenes from fullname.

    Many other member information fields would be optional under edit profile.

    If I can figure out how to select fullname from meta in wp_signups, adapting xprofile_sync_wp_profile() shouldn’t be that difficult.

    Or are my latest attempts above still nowhere near a solution? If you see the obvious mistakes, please point them out.

    @peterverkooijen

    Participant

    Mike Pratt, you’re right, that is one way to do it. Then you have the following fields on your registration form: username, name, first name, last name. That is an excellent solution if your aim is to annoy potential members.

    Another option is to use the default “fullname” field for first name and create a second one for last name, but then you’re kinda messing with the system and perhaps causing problems in the future. I have already done this solution in an earlier version. It’s my fallback option.

    But why would I have to create custom fields when WordPress already has the first_name and last_name fields in wp_usermeta? And there is even a ready-to-use Buddypress function that synchronizes the fields in wp_usermeta with the fullname in BP.

    Unfortunately at the moment that function is only run when the user updates his profile, so it’s completely useless. I’m trying to tweak it and make it useful and introduce to Buddypress the wonders of a first_name, last_name in the database. (Wow, I know…)

    Also I’d like to get rid of the username on the form, by autogenerating it from the fullname – make lowercase, take out spaces, store as username. That should be a relatively easy next step once I’ve figured out how to use the fullname input from the registration form in a function.

    Also I wasn’t able to get bp tags working in a plugin, where I had no problem pulling first_name and last_name from wp_usermeta, providing they were available…

    This should be a really easy plugin for any php coder, but as Jeff Sayre has pointed out, having a somewhat clean, professional user registration in Buddypress is reserved for those well-versed in the codebase or with deep-enough pockets.

    @Mariusooms, I need to finish the site before Labor Day, with a related event on September 22nd. When will bp1.0.3 be released?

    I’ll figure it out somehow, with or without the help of WordPress insiders.

    @peterverkooijen

    Participant

    Rogercoathup, if I can figure out this plugin, autogenerating a username from fullname is probably a small step that can be included in the same plugin. The big question is how to take fullname from the registration input (field_1) to do stuff with in a function. I think I’m getting closer, after about four months…

    Will get back to that later in the coming week.

    r-a-y, I doubt GigaOm would be eager to share their trade secrets. I’m also a bit of a potential competitor to them. Shh…

    @peterverkooijen

    Participant

    Couple of quick points:

    Transparancy is always key.

    Users want control over their own data.

    WP/WPMU/BP makes it very complicated to manage member data.

    And would it be a good choice to set creative commons licenses for certain types of data?

    I would NOT appreciate getting pushed into using this fake license from an academic with a political agenda, namely undermining copyright law and intellectual property rights. Creative Commons is slapping a fake label on something that already existed; public domain. I don’t work for Larry Lessig. I don’t have to ask Larry Lessig permission for anything.

    I am/was a journalist. The idea that all content should be free is basically destroying the media business. That’s great if you’re blogging from your mum’s basement, not great if you’re producing content to pay the rent – any content; text, video, design, code, etc.

    There is a lot of fluff and hypocrisy about open source, data portability etc. Facebook and Twitter are finding out the hard way. Everybody loves them when they’re free and open, but now they have to figure out how to make money to continue to pay employees when the venture capital money runs out.

    Proponents of giving stuff away for free are usually making their money some other way; they’re academics, work for the government, sell consulting services or hardware, live in their mum’s basement, etc. Google got rich and powerful claiming all content for themselves to sell ads in. Too many publishers went along and dug their own grave.

    So I’d like to keep a lot of data proprietary. There’s nothing wrong with that, as long as you’re clear and transparant about it. Publishers have always done it that way and technology does not necessarily require that to change.

    @peterverkooijen

    Participant

    This version also doesn’t work. No errors, registration goes through as normal, but still no first_name and last_name in wp_usermeta:

    function synchro_wp_usermeta($user_id, $password, $meta) {
    global $bp, $wpdb;

    $field_ids = $meta['xprofile_field_ids'];
    $field_ids = explode( ',', $field_ids );

    // Loop through each bit of profile data and save it to profile.
    for ( $i = 0; $i < count($field_ids); $i++ ) {
    if ( empty( $field_ids[$i] ) ) continue;

    $field_value = $meta["field_{$field_ids[$i]}"];

    $field = new BP_XProfile_ProfileData();
    $field->user_id = $user_id;
    $field->value = $field_value;
    $field->field_id = $field_ids[$i];
    $field->last_updated = time();

    $field->save();
    }

    $fullname = $field_value['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( $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 ) );
    }
    add_action( 'wpmu_activate_user', 'synchro_wp_usermeta', 10, 3);

    Again, any suggestions that can move this along are very much appreciated.

    The problem really is how to extract the fullname data from the meta field in wp_signups. Can I do something similar to this:

    xprofile_get_field_data( BP_XPROFILE_FULLNAME_FIELD_NAME, $bp->loggedin_user->id );

    Is there a wp_signups_get_field_data I can tap into?

    Or some type of database query?:

    $wpdb->read( $wpdb->signups, array('???' => 1), array('??' => $key) );

    @peterverkooijen

    Participant

    I had a good feeling about this attempt, but still nothing in wp_usermeta:

    function synchro_wp_usermeta($user_id, $password, $meta) {
    global $bp, $wpdb;

    $field_ids = $meta['xprofile_field_ids'];
    $field_ids = explode( ',', $field_ids );

    // Loop through each bit of profile data and save it to profile.
    for ( $i = 0; $i < count($field_ids); $i++ ) {
    if ( empty( $field_ids[$i] ) ) continue;

    $field_value = $meta["field_{$field_ids[$i]}"];
    }

    $fullname = $field_value['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( $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 ) );
    }
    add_action( 'wpmu_activate_user', 'synchro_wp_usermeta', 10, 3);

    This version messes up registration:

    function synchro_wp_usermeta($user_id, $password, $meta) {
    global $bp_user_signup_meta, $bp, $wpdb;

    $fields = BP_XProfile_Field::get_signup_fields();

    $field_ids = $meta['xprofile_field_ids'];
    $field_ids = explode( ',', $field_ids );

    // Loop through each bit of profile data and save it to profile.
    for ( $i = 0; $i < count($field_ids); $i++ ) {
    if ( empty( $field_ids[$i] ) ) continue;

    $field_value = $meta["field_{$field_ids[$i]}"];
    }

    $fullname = $field_value['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( $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 ) );
    }
    add_action( 'wpmu_activate_user', 'synchro_wp_usermeta', 10, 3);

    Registration goes through as normal. The user gets one email with the activation link. But the page on the link says ‘Your account has already been activated. You can now log in with the account details that were emailed to you.’ No email arrives.

    So the above code hijacks activation without doing anything (probably because $bp_user_signup_meta was added). Still nothing in wp_usermeta either.

    My problem is getting the $fullname from $meta. I don’t understand the array stuff. I’m basically just guessing.

    If there are any php coders out there that can spot any obvious mistakes or can suggest other things to try, please help me out.

    @peterverkooijen

    Participant

    You mean the 3 at the end of that line would fix that? I’ll try that next with a previous version of my code.

    Just for the record, this attempt again didn’t work. No errors, but nothing in wp_usermeta either:

    function synchro_wp_usermeta() {
    global $bp_user_signup_meta, $bp, $wpdb;

    $fields = BP_XProfile_Field::get_signup_fields();

    if ( $fields ) {
    foreach ( $fields as $field ) {

    $value = $_POST['field_' . $field->id];

    }
    }

    $fullname = $value['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( $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 ) );
    }
    add_action( 'wpmu_new_user', 'synchro_wp_usermeta' );

    This fixes the missing arguments errors, but still nothing in wp_usermeta. I’ll need to figure out how to serialize (?) $meta and extract $fullname from it:

    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( $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 ) );
    }
    add_action( 'wpmu_activate_user', 'synchro_wp_usermeta', 10, 3);

    @peterverkooijen

    Participant

    Thanks for the additional clues DJPaul!

    In the latest attempt I was going back to my first approach, trying to catch the input straight from the form, so that has to run on initial user registration, not on activation.

    Or is user_register not used in Buddypress at all? Is there a wpmu or bp equivalent I could try? Should I use wpmu_create_user? According to this blog post:

    the do_action for wpmu_new_user is directly at the bottom of wpmu_create_user in the wp-includes/wpmu-functions.php the wpmu_create_user gets sent the username password and email and checks if the username or email exists, if not create the new user in the database and assign a user_id to the return, also assigning capabilities and level … this happens on *all* levels of registration and is the perfect hook point to add them into the database

    the do_action do_action( ‘wpmu_new_user’, $user_id ); so you get the immediate user_id soon as it’s created which you can use in your table

    Apparantly this is like a flowchart of registration events in wpmu (wp-includes/wpmu-default-filters.php):

    add_filter ( 'wpmu_validate_user_signup', 'signup_nonce_check' );
    add_action ( 'init', 'maybe_add_existing_user_to_blog' );
    add_filter ( 'xmlrpc_methods', 'attach_wpmu_xmlrpc' );
    add_filter ( 'wp_authenticate_user', 'wordpressmu_authenticate_siteadmin', 10, 2 );
    add_action ( 'wpmu_new_user', 'newuser_notify_siteadmin' );
    add_action ( 'wpmu_activate_user', 'add_new_user_to_blog', 10, 3 );
    add_action ( 'sanitize_user', 'strtolower_usernames', 10, 3 );

    Should I focus on these wpmu action hooks instead of regular wp hook? Does bp have a list like this somewhere?

    I couldn’t figure out how to serialize that $meta data and extract the fullname from it, so I abandoned the approach hooking into wpmu_activate_user for now. Also when I put in the $user_id and $password arguments I got the error messages about missing arguments. wtf?!

    I think this bit of code grabs the input from the registration form:

    $fields = BP_XProfile_Field::get_signup_fields();

    if ( $fields ) {
    foreach ( $fields as $field ) {

    $value = $_POST['field_' . $field->id];

    fullname is the input from field_1, but I don’t know how to finish the php to get to $fullname = … . The two latest attempts above did not work.

    I have to give up for now. Deadline at my day job coming up…

    @peterverkooijen

    Participant

    The last attempt in the previous post does not work. No error messages, registration goes through as normal, but nothing in wp_usermeta.

    This also has no effect:

    function synchro_wp_usermeta() {
    global $bp_user_signup_meta, $bp, $wpdb;

    $fields = BP_XProfile_Field::get_signup_fields();

    if ( $fields ) {
    foreach ( $fields as $field ) {

    $fullname = $_POST['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( $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 ) );
    }
    add_action( 'user_register', 'synchro_wp_usermeta' );

    Please, I need feedback to finish this function/plugin. A real coder can spot the problem probably immediately. Please point it out, don’t leave me hanging.

    @peterverkooijen

    Participant

    Stuck again…

    I think this is the function that takes the input from the registration form (in bp_xprofile_classes.php):

    function get_signup_fields() {
    global $wpdb, $bp;

    $sql = $wpdb->prepare( "SELECT f.id FROM {$bp->profile->table_name_fields} AS f, {$bp->profile->table_name_groups} AS g WHERE g.name = %s AND f.parent_id = 0 AND g.id = f.group_id ORDER BY f.id", get_site_option('bp-xprofile-base-group-name') );

    if ( !$temp_fields = $wpdb->get_results($sql) )
    return false;

    for ( $i = 0; $i < count($temp_fields); $i++ ) {
    $fields[] = new BP_XProfile_Field( $temp_fields[$i]->id, null, false );
    }

    return $fields;
    }

    Then bp-xprofile-signup.php has the function xprofile_load_signup_meta() with this bit:

    $fields = BP_XProfile_Field::get_signup_fields();

    if ( $fields ) {
    foreach ( $fields as $field ) {

    $value = $_POST['field_' . $field->id];

    Followed by lots of validation code. For my purposes I could end it here:

    $fullname = $_POST['field_1'];

    Trying to put it together:

    function synchro_wp_usermeta() {
    global $bp_user_signup_meta, $bp, $wpdb;

    $fields = BP_XProfile_Field::get_signup_fields();

    if ( $fields ) {
    foreach ( $fields as $field ) {

    $value = $_POST['field_' . $field->id];

    }
    }

    $fullname = $value['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( $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 ) );
    }
    add_action( 'user_register', 'synchro_wp_usermeta' );

    Does this make sense? Can any of the more experienced php-coders please point out the obvious mistakes?

Viewing 25 replies - 501 through 525 (of 690 total)
Skip to toolbar