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
- This topic has 3 replies, 2 voices, and was last updated 7 years, 2 months ago by
nullsignature.
-
AuthorPosts
-
August 31, 2018 at 9:51 pm #15055
nullsignature
MemberI’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
September 1, 2018 at 5:56 am #78454admin
KeymasterThe 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);September 3, 2018 at 2:20 pm #78455nullsignature
MemberThanks! I’ll give this a shot.
September 3, 2018 at 2:55 pm #78456nullsignature
MemberEdit: 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'); -
AuthorPosts
- You must be logged in to reply to this topic.