Question

I have a software and a wordpress installed in the same database, there is a wordpress "user" table and the software "user_soft" table. Is there any way or plugin to sync the two tables so that when the user register in wordpress, automatically register in "user_soft"?

Was it helpful?

Solution

Welcome to WPSE. Asking for plugin recommendations is considered off-topic here, so here's an action approach to the problem.

wp_insert_user() takes care of adding new users to the database. The last action the function fires is user_register, which "Fires immediately after a new user is registered". You could hook your function to this action and use it to update the custom DB table.

In your action function you can use the global $wpdb to manipulate your database tables whether they are standard WP tables or not. (You can also use wpdb class to connect to other databases, too.)

To insert new data into the database you can use the wpdb::insert( string $table, array $data, array|string $format = null ) method.

If there's some user data that needs to be kept updated and synced, then you can hook to profile_update action, which wp_insert_user() also fires, but "...immediately after an existing user is updated".

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top