Create user account in WordPress website on login using info from external database


Staff member
I have a PHP website that has its own users in a MySQL database. That website is "alive" so new user accounts will continue to be created for undefined time.

Now I have to create another website using WP, with these 2 particularities:

<li>Some sections of the website can only be accessed when the user logs into the website</li>
<li>The users who can access this WP website are <strong>some</strong> of the users in the users table used by the first website. This is important because <strong>not all</strong> those users will have access, only the ones that have one of the fields in that table with certain values.</li>

The <strong>first way</strong> of accomplishing this that I've thought about is to create a custom login function that does all the processing, without having wordpress create any sort of user account on its own for those users. I'm not a WP developer but I guess that with some research I could find out how to do that.

The issue with that option is that I plan on including a forum and maybe other features that will in fact require user accounts in WP to keep track of comments, posts, etc

So why I would like to seek advice for is <strong>how to approach all this</strong>. Ideally, what I would need is an implementation that:

<li>Asks for login when users want to access certain sections of the site</li>
<li>Checks user credentials in an external database on login, using a custom function that validates not just username and password, but also a third (or even a fourth) field</li>
<li>On login, if it's the first time, creates an account for that user in WP using the information that the user has in the other website, but blocking any typical account management functions (change profile info, password, etc)</li>

I know that with some coding it all can be done, I'm just don't know very much about about Wordpress so I don't know if all that would be too complicated.

<strong>Anther option</strong> that I have in mind would be to create the user accounts in WP right when the account in the original website is created, but I don't know if that's even possible in a "legit" way (to create an account for the WP from another website).

Any advice on this topic would be really appreciated