Query runs on x-profile edit, but not on registration
-
Hey,
I had a problem with a code which I customized from a forum topic, but absolutely have no idea why it doesn’t work.
I have a query in the code to upgrade the display name for the user on registration, activation, and x-profile edit. Unfortunately it only works on profile editing. The strange thing is that I put another query (a simple INSERT INTO query, which insert the user ID and the new display name into a test table) to test if my code run, and that query runs both registration and activation too. I work with 5.1.1 WordPress version and BuddyPress version 4.2.0. Profile sync is also enabled.Here is my code:
function xprofile_sync_wp_profile2( $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; } global $wpdb; // Get name from x-fields $display_name = xprofile_get_field_data('Név',$user_id ); //Test query to detect if the function run, works every time $wpdb->query("INSERT INTO test (id, name) VALUES ('".$user_id."', '".$display_name."');"); //Query to update display_name, works only on x-profile edit $wpdb->query( $wpdb->prepare( "UPDATE wphu_users SET display_name = '%s' WHERE ID = %d", $display_name, $user_id ) ); } add_action( 'xprofile_updated_profile', 'xprofile_sync_wp_profile2' ); add_action( 'bp_core_signup_user', 'xprofile_sync_wp_profile2' ); add_action( 'bp_core_activated_user', 'xprofile_sync_wp_profile2' );
Thanks for your help & replies,
David
- You must be logged in to reply to this topic.