Support » Plugin: Import Users from CSV » Add existing user to blog instead of throw error?

  • Resolved plugins_lexblog

    (@plugins_lexblog)


    Hey,

    Awesome plugin. Works great and is very simple. Great work.

    One question: I notice that if the plugin encounters an existing username/email address among the spreadsheet data, it just adds that user to the error log and moves on. We would like to see this instead:

    The plugin should still log this, but instead of just skipping the user, it should add the existing user to the current blog (this is only relevant in a WPMU setup).

    Any thoughts on adding this as a checkbox option? Any advice on hacking the plugin code myself in pursuit of this?

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

Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author Ulrich Sossou

    (@sorich87)

    Thank you for the response, Ulrich.

    I guess I was thinking about something more like,

    http://codex.wordpress.org/Function_Reference/username_exists

    http://codex.wordpress.org/Function_Reference/email_exists

    if(username_exists() || email_exists()) {
        just add the guy to this blog and log this in the log.
    }

    Does that make sense? I saw the function you pasted in the other thread, but I didn’t see how that would apply here.

    Plugin Author Ulrich Sossou

    (@sorich87)

    Something like this should work (not tested).

    function example_add_user_to_blog( $userdata ) {
      global $wpdb;
    
      if ( username_exists( $userdata['user_login'] ) || email_exists( $userdata['user_email'] ) ) {
        if ( $userdata['user_login'] )
          $user = get_user_by( 'login', $userdata['user_login'] );
        else
          $user = get_user_by( 'email', $userdata['user_email'] );
    
        add_user_to_blog( $wpdb->blog_id, $user_id, $userdata['role'] );
    
        $userdata['ID'] = $user->ID;
      }
    
      return $userdata;
    }
    add_filter( 'is_iu_import_userdata', 'example_filter_import_userdata' );

    Awesome, thank you. I ended up adding a modified part of that snippet to line 280 of your plugin:

    if ( username_exists( $userdata['user_login'] ) || email_exists( $userdata['user_email'] ) ) {
            		if ( $userdata['user_login'] ) {
              			$user = get_user_by( 'login', $userdata['user_login'] );
            		} else {
              			$user = get_user_by( 'email', $userdata['user_email'] );
    				}
            		$user_id = add_user_to_blog( get_current_blog_id(), $user->ID, $userdata['role'] );
    
    		        $userdata['ID'] = $user->ID;
    
          		}

    Obviously, that’s going to bite the dust whenever we update your plugin. Would you consider integrating this, or something similar, into your plugin?

    Plugin Author Ulrich Sossou

    (@sorich87)

    I will consider it.

    Why didn’t you add the snippet in your theme functions.php file or somewhere else it won’t be affected by an update?

    Very good question.

    1) We use the same parent theme across hundreds of blogs, so we try to avoid adding code that will only apply to any small subset of them (which this would, in our case).

    2) We try to avoid making any changes at all to the parent theme because we are in a very demanding vertical and it’s not feasible to test code changes to the parent theme across all our blogs.

    3) It would be tedious to remember to add this in the child theme of every blog that needs it.

    4) We could just write another plugin to include this as necessary, but it will be difficult to remember to activate our plugin every time we activate your plugin.

    5) We’re already running a ton of plugins that are network activated. We’re trying to cut back as it is, so network activating this AND our patch is not an option.

    6) It’s a good update! Maybe include it as a conditional based on an option in the management page?

    Plugin Author Ulrich Sossou

    (@sorich87)

    Thanks for explaining. I will add it.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Add existing user to blog instead of throw error?’ is closed to new replies.