Last active
May 2, 2016 19:51
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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