Wordpress表关联

I have a partially completed plug in for WP that integrates Easy!Appointments scheduling utility into the WP database. I need to associate the Easy!Appointments user with the WP user.

STRUCTURE:

The Easy!Appointments database is part of the WP database structure in mysql. Easy!Appointments is built in the Codeigniter Framework. Easy!Appointments runs in an iframe within WP.

In Easy!Appointments, the users table is ea_users, I know I will need to create another column in the ea user table for wp_id. So, I will create that column.

ALTER TABLE `ea_users` ADD `wp_id` BIGINT(20) NOT NULL ;

In the wp_users table I need id and user_email fields to be associated with in the ea_users table with wp_id and email fields respectively.

Can this just be done in mysql with an association of some sort? (that would be nice)

Or do I need some php code that will (in sudo code):

On creating an E!A booking, check if the `wp_id` column for the user is null

 if is null: Get the the `wp_users` table, `user_email`  and current `id` and fill the `ea_users` table `wp_id` and `email`.

 else: check for matching `wp_users` `id` and `ea_users`  `wp_id`   

      if yes: match `ea_users`  `wp_id`   user with `wp_users` `id` and fill existing EA user data in to EA fields

      if no: delete the `ea_users`  `wp_id`   and get the `wp_users` table, `user_email`  and fill the `ea_users`  table `wp_id` and `email`.

If I must do the PHP then I think that would do it. Let me know if my logic is off. Also, I have to remember how to do this so any quick pointers there would be appreciated but not expected.

QUESTIONS:

  1. Can I simply link the two tables in mysql with an association of some sort (I doubt it)?

  2. Does my logic in my pseudocode look about right? Is there a step I may be missing?

  3. Do you have any tips regarding how to get this done in PHP. For example, are there some built in functions in WP to get this done?

Answer to question 1 is no.
Answer to question 2 is I think my logic is ok.
Answer to question 3 is yes there are some built in WP functions for this and the one I need is wp_get_current_user() and get_current_user_id().

So, this much of this problem is answered. I now have questions about codeigniter integration.