Skip to main content
added 505 characters in body
Source Link
Interactive
  • 1k
  • 3
  • 16
  • 36
  • EDIT -
    I have come so far but I can't get the last part to work. I have the adding of a new user fixed.
    The foreach loops through the csv to add all users:

      $filepath = get_bloginfo('template_directory')."/import_test.csv";
      ini_set('auto_detect_line_endings',TRUE);
      $file = fopen($filepath, "r") or die("Error opening file");
      $i = 0;
    
      while(($line = fgetcsv($file, 1000, ";")) !== FALSE) {
          if($i == 0) {
              $c = 0;
              foreach($line as $col) {
                  $cols[$c] = $col;
                  $c++;
              }
          } else if($i > 0) {
                  $c = 0;
                  foreach($line as $col) {
              $data[$i][$cols[$c]] = $col;
          $data[$i][$cols[$c]] = $col;  $c++;
          }
      }
      $i++;
    

    }

      foreach ($data as $gebruiker){
       $c++;
       $username = $gebruiker['username'];
          if ( username_exists( }$username ) ){
              }
    $user = get_user_by( 'login', $username);
            $i++;
      update_user_meta( $user->ID, 'meta_key', $gebruiker['email'] }
    );
          foreach}
     ($data as $user)   else{
              $user$users = wp_insert_user(
                  array(
                  'user_login'    =>  $user['username']$gebruiker['username'],
                  'user_pass'     =>  $user['password']$gebruiker['password'],
                  'first_name'    =>  $user['first_name']$gebruiker['first_name'],
                  'last_name'     =>  $user['last_name']$gebruiker['last_name'],
                  'user_email'    =>  $user['email']$gebruiker['email'],
                  'display_name'  =>  $user['first_name']$gebruiker['first_name'] . ' ' . $user['last_name']$gebruiker['last_name'],
                  'nickname'      =>  $user['first_name']$gebruiker['first_name'] . '' . $user['last_name']$gebruiker['last_name'],
                  'role'          =>  'subscriber'
                  )                       
              );
              foreach ($data as $update_user) {   
                  update_user_meta( $users, 'import_1', $update_user['first_name'] );
                  update_user_meta( $users, 'import_2', $update_user['last_name'] );
              }
          }
      }
    

But no matter where I place the update_user_meta in the loop it gives me back the following error: Fatal error: Cannot use object of type WP_Error as array in
The error is fixed. Because the users allready existed. So need to check for that later. This does mean that the fields are added to the usermeta but empty

====== EDIT ======
The above code is final and working...

  • EDIT -
    I have come so far but I can't get the last part to work. I have the adding of a new user fixed.
    The foreach loops through the csv to add all users:

      $filepath = get_bloginfo('template_directory')."/import_test.csv";
      ini_set('auto_detect_line_endings',TRUE);
      $file = fopen($filepath, "r") or die("Error opening file");
      $i = 0;
    
      while(($line = fgetcsv($file, 1000, ";")) !== FALSE) {
          if($i == 0) {
              $c = 0;
              foreach($line as $col) {
                  $cols[$c] = $col;
                  $c++;
              }
          } else if($i > 0) {
                  $c = 0;
                  foreach($line as $col) {
                      $data[$i][$cols[$c]] = $col;
                      $c++;
                  }
              }
              $i++;
          }
    
          foreach ($data as $user){
              $user = wp_insert_user(
                  array(
                  'user_login'    =>  $user['username'],
                  'user_pass'     =>  $user['password'],
                  'first_name'    =>  $user['first_name'],
                  'last_name'     =>  $user['last_name'],
                  'user_email'    =>  $user['email'],
                  'display_name'  =>  $user['first_name'] . ' ' . $user['last_name'],
                  'nickname'      =>  $user['first_name'] . '' . $user['last_name'],
                  'role'          =>  'subscriber'
                  )
              );
      }
    

But no matter where I place the update_user_meta in the loop it gives me back the following error: Fatal error: Cannot use object of type WP_Error as array in
The error is fixed. Because the users allready existed. So need to check for that later. This does mean that the fields are added to the usermeta but empty

  • EDIT -
    I have come so far but I can't get the last part to work. I have the adding of a new user fixed.
    The foreach loops through the csv to add all users:

      $filepath = get_bloginfo('template_directory')."/import_test.csv";
      ini_set('auto_detect_line_endings',TRUE);
      $file = fopen($filepath, "r") or die("Error opening file");
      $i = 0;
    
      while(($line = fgetcsv($file, 1000, ";")) !== FALSE) {
          if($i == 0) {
          $c = 0;
          foreach($line as $col) {
              $cols[$c] = $col;
              $c++;
          }
      } else if($i > 0) {
      $c = 0;
          foreach($line as $col) {
              $data[$i][$cols[$c]] = $col;
              $c++;
          }
      }
      $i++;
    

    }

      foreach ($data as $gebruiker){
          $username = $gebruiker['username'];
          if ( username_exists( $username ) ){
              $user = get_user_by( 'login', $username);
              update_user_meta( $user->ID, 'meta_key', $gebruiker['email'] );
          }
          else{
              $users = wp_insert_user(
                  array(
                  'user_login'    =>  $gebruiker['username'],
                  'user_pass'     =>  $gebruiker['password'],
                  'first_name'    =>  $gebruiker['first_name'],
                  'last_name'     =>  $gebruiker['last_name'],
                  'user_email'    =>  $gebruiker['email'],
                  'display_name'  =>  $gebruiker['first_name'] . ' ' . $gebruiker['last_name'],
                  'nickname'      =>  $gebruiker['first_name'] . '' . $gebruiker['last_name'],
                  'role'          =>  'subscriber'
                  )                       
              );
              foreach ($data as $update_user) {   
                  update_user_meta( $users, 'import_1', $update_user['first_name'] );
                  update_user_meta( $users, 'import_2', $update_user['last_name'] );
              }
          }
      }
    

But no matter where I place the update_user_meta in the loop it gives me back the following error: Fatal error: Cannot use object of type WP_Error as array in
The error is fixed. Because the users allready existed. So need to check for that later. This does mean that the fields are added to the usermeta but empty

====== EDIT ======
The above code is final and working...

added 159 characters in body
Source Link
Interactive
  • 1k
  • 3
  • 16
  • 36

But no matter where I place the update_user_meta in the loop it gives me back the following error: Fatal error: Cannot use object of type WP_Error as array in
The error is fixed. Because the users allready existed. So need to check for that later. This does mean that the fields are added to the usermeta but empty

But no matter where I place the update_user_meta in the loop it gives me back the following error: Fatal error: Cannot use object of type WP_Error as array in

But no matter where I place the update_user_meta in the loop it gives me back the following error: Fatal error: Cannot use object of type WP_Error as array in
The error is fixed. Because the users allready existed. So need to check for that later. This does mean that the fields are added to the usermeta but empty

added 1497 characters in body
Source Link
Interactive
  • 1k
  • 3
  • 16
  • 36
  • EDIT -
    I have come so far but I can't get the last part to work. I have the adding of a new user fixed.
    The foreach loops through the csv to add all users:

      $filepath = get_bloginfo('template_directory')."/import_test.csv";
      ini_set('auto_detect_line_endings',TRUE);
      $file = fopen($filepath, "r") or die("Error opening file");
      $i = 0;
    
      while(($line = fgetcsv($file, 1000, ";")) !== FALSE) {
          if($i == 0) {
              $c = 0;
              foreach($line as $col) {
                  $cols[$c] = $col;
                  $c++;
              }
          } else if($i > 0) {
                  $c = 0;
                  foreach($line as $col) {
                      $data[$i][$cols[$c]] = $col;
                      $c++;
                  }
              }
              $i++;
          }
    
          foreach ($data as $user){
              $user = wp_insert_user(
                  array(
                  'user_login'    =>  $user['username'],
                  'user_pass'     =>  $user['password'],
                  'first_name'    =>  $user['first_name'],
                  'last_name'     =>  $user['last_name'],
                  'user_email'    =>  $user['email'],
                  'display_name'  =>  $user['first_name'] . ' ' . $user['last_name'],
                  'nickname'      =>  $user['first_name'] . '' . $user['last_name'],
                  'role'          =>  'subscriber'
                  )
              );
      }
    

To add files to the wp_usermeta table I want to work with update_user_meta since the wp_insert_user comes back with an ID of the just created user.

But no matter where I place the update_user_meta in the loop it gives me back the following error: Fatal error: Cannot use object of type WP_Error as array in

  • EDIT -
    I have come so far but I can't get the last part to work. I have the adding of a new user fixed.
    The foreach loops through the csv to add all users:

      $filepath = get_bloginfo('template_directory')."/import_test.csv";
      ini_set('auto_detect_line_endings',TRUE);
      $file = fopen($filepath, "r") or die("Error opening file");
      $i = 0;
    
      while(($line = fgetcsv($file, 1000, ";")) !== FALSE) {
          if($i == 0) {
              $c = 0;
              foreach($line as $col) {
                  $cols[$c] = $col;
                  $c++;
              }
          } else if($i > 0) {
                  $c = 0;
                  foreach($line as $col) {
                      $data[$i][$cols[$c]] = $col;
                      $c++;
                  }
              }
              $i++;
          }
    
          foreach ($data as $user){
              $user = wp_insert_user(
                  array(
                  'user_login'    =>  $user['username'],
                  'user_pass'     =>  $user['password'],
                  'first_name'    =>  $user['first_name'],
                  'last_name'     =>  $user['last_name'],
                  'user_email'    =>  $user['email'],
                  'display_name'  =>  $user['first_name'] . ' ' . $user['last_name'],
                  'nickname'      =>  $user['first_name'] . '' . $user['last_name'],
                  'role'          =>  'subscriber'
                  )
              );
      }
    

To add files to the wp_usermeta table I want to work with update_user_meta since the wp_insert_user comes back with an ID of the just created user.

But no matter where I place the update_user_meta in the loop it gives me back the following error: Fatal error: Cannot use object of type WP_Error as array in

changed it all
Source Link
Interactive
  • 1k
  • 3
  • 16
  • 36
Loading
added 8 characters in body; edited tags
Source Link
cybmeta
  • 20.6k
  • 5
  • 47
  • 56
Loading
Source Link
Interactive
  • 1k
  • 3
  • 16
  • 36
Loading