WordPress.org

Ready to get started?Download WordPress

Forums

Import Users from CSV
[resolved] Import via cron event (3 posts)

  1. Ulrich Sossou
    Member
    Plugin Author

    Posted 2 years ago #

    How to schedule a cron event that will import users from a specified file on the server?

    I had a user ask me by email how to do that, so I released version 0.5 to make the plugin more extensible and I am posting the solution here for anyone who would like to do that in the future.

    The plugin now has a function called IS_IU_Import_Users::import_csv( string $filename, bool, bool ).
    The first argument is the path to the file on the server.
    The second one is whether you want the password nag to be shown on first user login.
    The third one is whether you want to send email notifications to the new users.

    Below is the code to schedule the daily event.

    function is_iu_schedule_event() {
        if ( ! wp_next_scheduled( 'is_iu_daily_event' ) ) {
            wp_schedule_event( time(), 'hourly', 'is_iu_daily_event' );
        }
    }
    add_action( 'wp', 'is_iu_schedule_event' );
    
    function is_iu_do_this_daily() {
        IS_IU_Import_Users::import_csv( PATH_TO_YOUR_CSV_FILE );
    }
    add_action( 'is_iu_daily_event', 'is_iu_do_this_daily' );

    This code can be added to a plugin or your theme functions.php file
    Make sure to replace PATH_TO_YOUR_CSV_FILE with the actual path to your csv file on the server.

    http://wordpress.org/extend/plugins/import-users-from-csv/

  2. af3
    Member
    Posted 2 years ago #

    This is cool.

    How to make this to update the existing users (except password)? and add new users not already in the database?

  3. Ulrich Sossou
    Member
    Plugin Author

    Posted 2 years ago #

    Add an ID column in your CSV and put the ID for existing users in there

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic