• Resolved zeridon

    (@zeridon)


    Hello All,

    I am trying to migrate a site which unfortunately still uses CSV file as a user database. The idea is to move the users into wordpress and deal with them there.

    Currently my plan is on login attempt to check if the user does not exists in wp and if not check the csv. If it is found in the csv add it to wp database and let the normal authentication do the job.

    But unfortunately i am a little bit stuck. I reached to the conclusion it is best to use the wp_authenticate action hook (don’t really want to overload the function itself) but i am amiss what vars are available at that time.

    Also i don’t really know when the hook (and related functions connected to it) is executed.

    So is there a better way to do it or can someone give me hints on my solution.

Viewing 4 replies - 1 through 4 (of 4 total)
  • So is there a better way to do it…

    Since you asked… why don’t you just loop through your csv file ( either line by line or read it into an array ), add the users, and be done with it?

    Thread Starter zeridon

    (@zeridon)

    One of the purposes is relatively easy filtering of inactive members. I don’t want to import all of them or i will be stuck with the task of cleaning them. Just by having this i can leave the plugin active for 6 – 8 months and after that just shut it off.

    Drop this in you theme’s functions.php and try to log in.

    function test_wp_auth() {
      print_r(get_defined_vars());
      exit; // sometime needed; sometimes not
    }
    add_action('wp_authenticate','test_wp_auth');

    Now you know what variables you have available.

    However, I’d still not do it the way are doing it. It just seems like more work to me to interrupt the login process to add users dynamically. …could just be a personality glitch ?? I’d add all the users in one shot a simple ‘last_login’ tracker like this:

    function my_user_last_login($login) {
        global $user_ID;
        $user = get_userdatabylogin($login);
        update_usermeta( $user->ID, 'my_user_last_login', time() );
    }
    add_action('wp_login','my_user_last_login');

    Then after six months or so remove any users who haven’t logged in.

    Thread Starter zeridon

    (@zeridon)

    Thanks for the hint, didn’t knew about get_defined_vars

    The tracker idea is nice and will also implement it as it will be good for cleaning up dead souls.

    Additionally i stumbled on something minor. If user_nicename is not in latin it get’s filtered out (i.e. set to empty).

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘How to authenticate against CSV file’ is closed to new replies.