Skip to content

Instantly share code, notes, and snippets.

@inderpreet99
Last active May 2, 2016 19:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save inderpreet99/b0742f02426af72f66c12f1f63bebdf8 to your computer and use it in GitHub Desktop.
Save inderpreet99/b0742f02426af72f66c12f1f63bebdf8 to your computer and use it in GitHub Desktop.
During WP Import, run the following script in Chrome DevTools console to assign authors automatically. Make jQuery contains case-insensitive for best results: http://stackoverflow.com/questions/187537/is-there-a-case-insensitive-jquery-contains-selector
jQuery('#authors li').each(function(index) {
var user = jQuery(this).find('strong').text();
var re = /^(.*)\s\(([\w\s]*)\)/;
var match = user.match(re);
var name = match[1];
var username = match[2];
console.log('user: ' + user);
var usermap = jQuery(this).find('select');
var select_username = jQuery(usermap).find('option:contains("' + username + '")').attr('selected', true);
if ( select_username.length == 0 ) {
var select_name = jQuery(usermap).find('option:contains("' + name + '")').attr('selected', true);
} else if ( select_username.length > 1 ) {
console.log(select_username);
}
} );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment