- This topic has 3 replies, 2 voices, and was last updated 6 years, 1 month ago by .
Viewing 4 posts - 1 through 4 (of 4 total)
Viewing 4 posts - 1 through 4 (of 4 total)
- You must be logged in to reply to this topic.
Support site for Tips and Tricks HQ premium products
by
Tips and Tricks HQ Support Portal › Forums › WP eMember › WP eMember Tweaks › When a user registers I'd like to add their member_id to a different table
Tagged: customization, Tweaks, wp membership
I’ve built a separate MySQL table (user history, in the same database as wordpress) for a specific tool and would like to insert the eMember ID into it whenever someone registers (in addition to the normal database handling for eMember). I assume eMember_registration_utils.php is the best page to do this. What is the best function/line to insert this on? And the best way to get the member_id of the user that just registered? Basically, I just want to add something like this this:
$wpdb->insert(‘user_history’, array(‘userid’ => $memberid>);
Where
user_history is my table
userid is the name of the column
$memberid is the ID of the newly registered user under eMember
The best option is to use our registration complete hook. That way you are not modifying the core plugin files.
Here is the action hook:
eMember_registration_complete
Below is an example snippet of code that shows how to use this hook:
function handle_registration_complete_event($member_data, $custom_fields)
{
//The following line will print all the member details that got passed to this function
//You can use this data to insert it to your table.
print_r($member_data);
}
add_action('eMember_registration_complete','handle_registration_complete_event',10,2);
Thanks! I’ll give this a shot.
Edit: figured it out. $member_data is an array that doesn’t need to be passed by add_action. Here’s my code for any future searchers. This inserts the newly registered user’s ID into a table called user_question_history.
function handle_eMember_registration_complete_event($member_data)
{
global $wpdb;
$wpdb->insert('user_question_history', array('user_id' => $member_data['member_id']));
}
add_action('eMember_registration_complete','handle_eMember_registration_complete_event');