Changeset 681718
- Timestamp:
- 03/14/2013 10:22:53 AM (13 years ago)
- Location:
- import-users-from-csv/trunk
- Files:
-
- 3 edited
-
examples/import.csv (modified) (1 diff)
-
import-users-from-csv.php (modified) (10 diffs)
-
readme.txt (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
import-users-from-csv/trunk/examples/import.csv
r477250 r681718 1 1 "user_login","user_email","user_pass","first_name","last_name","display_name","role","custom_usermeta_1","custom_usermeta_2" 2 2 "johndoe","john.doe@localhost.localdomain",,"John","Doe","John Doe","administrator","Test","Test" 3 "janedoe","jane.doe@localhost.localdomain.com","test","Jane","Doe","Jane Doe","contributor", ,3 "janedoe","jane.doe@localhost.localdomain.com","test","Jane","Doe","Jane Doe","contributor","0", -
import-users-from-csv/trunk/import-users-from-csv.php
r507550 r681718 5 5 /* 6 6 Plugin Name: Import Users from CSV 7 Plugin URI: http:// pubpoet.com/plugins/7 Plugin URI: http://wordpress.org/extend/plugins/import-users-from-csv/ 8 8 Description: Import Users data and metadata from a csv file. 9 Version: 0. 5.110 Author: PubPoet11 Author URI: http:// pubpoet.com/9 Version: 0.6 10 Author: Ulrich Sossou 11 Author URI: http://ulrichsossou.com/ 12 12 License: GPL2 13 13 Text Domain: import-users-from-csv … … 79 79 $filename = $_FILES['users_csv']['tmp_name']; 80 80 $password_nag = isset( $_POST['password_nag'] ) ? $_POST['password_nag'] : false; 81 $users_update = isset( $_POST['users_update'] ) ? $_POST['users_update'] : false; 81 82 $new_user_notification = isset( $_POST['new_user_notification'] ) ? $_POST['new_user_notification'] : false; 82 83 83 $results = self::import_csv( $filename, $password_nag, $new_user_notification ); 84 $results = self::import_csv( $filename, array( 85 'password_nag' => $password_nag, 86 'new_user_notification' => $new_user_notification, 87 'users_update' => $users_update 88 ) ); 84 89 85 90 // No users imported? … … 154 159 <table class="form-table"> 155 160 <tr valign="top"> 156 <th scope="row"><label for"users_csv"><?php _e( 'CSV file' , 'import-users-from-csv'); ?></label></th> 157 <td><input type="file" id="users_csv" name="users_csv" value="" class="all-options" /></td> 161 <th scope="row"><label for="users_csv"><?php _e( 'CSV file' , 'import-users-from-csv'); ?></label></th> 162 <td> 163 <input type="file" id="users_csv" name="users_csv" value="" class="all-options" /><br /> 164 <span class="description"><?php echo sprintf( __( 'You may want to see <a href="%s">the example of the CSV file</a>.' , 'import-users-from-csv'), plugin_dir_url(__FILE__).'examples/import.csv'); ?></span> 165 </td> 158 166 </tr> 159 167 <tr valign="top"> … … 163 171 <label for="new_user_notification"> 164 172 <input id="new_user_notification" name="new_user_notification" type="checkbox" value="1" /> 165 Send to new users173 <?php _e('Send to new users', 'import-users-from-csv') ?> 166 174 </label> 167 175 </fieldset></td> … … 173 181 <label for="password_nag"> 174 182 <input id="password_nag" name="password_nag" type="checkbox" value="1" /> 175 Show password nag on new users signon 183 <?php _e('Show password nag on new users signon', 'import-users-from-csv') ?> 184 </label> 185 </fieldset></td> 186 </tr> 187 <tr valign="top"> 188 <th scope="row"><?php _e( 'Users update' , 'import-users-from-csv'); ?></th> 189 <td><fieldset> 190 <legend class="screen-reader-text"><span><?php _e( 'Users update' , 'import-users-from-csv' ); ?></span></legend> 191 <label for="users_update"> 192 <input id="users_update" name="users_update" type="checkbox" value="1" /> 193 <?php _e( 'Update user when a username or email exists', 'import-users-from-csv' ) ;?> 176 194 </label> 177 195 </fieldset></td> … … 179 197 </table> 180 198 <p class="submit"> 181 <input type="submit" class="button-primary" value="<?php _e( 'Import' , 'import-users-from-csv'); ?>" />199 <input type="submit" class="button-primary" value="<?php _e( 'Import' , 'import-users-from-csv'); ?>" /> 182 200 </p> 183 201 </form> … … 190 208 * @since 0.5 191 209 */ 192 public static function import_csv( $filename, $ password_nag = false, $new_user_notification = false) {210 public static function import_csv( $filename, $args ) { 193 211 $errors = $user_ids = array(); 212 213 $defaults = array( 214 'password_nag' => false, 215 'new_user_notification' => false, 216 'users_update' => false 217 ); 218 extract( wp_parse_args( $args, $defaults ) ); 194 219 195 220 // User data fields list used to differentiate with user meta … … 236 261 $column = trim( $column ); 237 262 238 if ( empty( $column ) )239 continue;240 241 263 if ( in_array( $column_name, $userdata_fields ) ) { 242 264 $userdata[$column_name] = $column; … … 257 279 do_action( 'is_iu_pre_user_import', $userdata, $usermeta ); 258 280 259 // Are we updating an old user or creating a new one? 281 $user = $user_id = false; 282 283 if ( isset( $userdata['ID'] ) ) 284 $user = get_user_by( 'ID', $userdata['ID'] ); 285 286 if ( ! $user && $users_update ) { 287 if ( isset( $userdata['user_login'] ) ) 288 $user = get_user_by( 'login', $userdata['user_login'] ); 289 290 if ( ! $user && isset( $userdata['user_email'] ) ) 291 $user = get_user_by( 'email', $userdata['user_email'] ); 292 } 293 260 294 $update = false; 261 $user_id = 0;262 if ( ! empty( $userdata['ID'] ) ) {295 if ( $user ) { 296 $userdata['ID'] = $user->ID; 263 297 $update = true; 264 $user_id = $userdata['ID'];265 298 } 266 299 … … 269 302 $userdata['user_pass'] = wp_generate_password( 12, false ); 270 303 271 // Insert or update... at last! If only user ID was provided, we don't need to do anything at all. :) 272 if ( array( 'ID' => $user_id ) == $userdata ) 273 $user_id = get_userdata( $user_id )->ID; // To check if the user id exists 274 else if ( $update ) 304 if ( $update ) 275 305 $user_id = wp_update_user( $userdata ); 276 306 else -
import-users-from-csv/trunk/readme.txt
r507550 r681718 3 3 Tags: user, users, csv, batch, import, importer, admin 4 4 Requires at least: 3.1 5 Tested up to: 3. 46 Stable tag: 0. 5.15 Tested up to: 3.6 6 Stable tag: 0.6 7 7 8 8 Import users from a CSV file into WordPress … … 29 29 For feature request and bug reports, [please use the forums](http://wordpress.org/tags/import-users-from-csv?forum_id=10#postform). 30 30 Code contributions are welcome [on Github](https://github.com/sorich87/Import-Users-from-CSV). 31 32 = Tutorials =33 [How to Update Existing Users with "Import Users from CSV"](http://pubpoet.com/2011/05/28/update-users-import-users-csv/)34 31 35 32 == Installation == … … 72 69 You can try importing that file and look at the result. 73 70 74 = How to Update Existing Users? =75 76 See [How to Update Existing Users with "Import Users from CSV"](http://pubpoet.com/2011/05/28/update-users-import-users-csv/)77 78 71 == Screenshots == 79 72 … … 81 74 82 75 == Changelog == 76 77 = 0.6 = 78 * Fixed bug where importing fields with "0" value doesn't work 79 * Added option to update existing users by username or email 83 80 84 81 = 0.5.1 =
Note: See TracChangeset
for help on using the changeset viewer.