【问题】
使用wordpress Importer导入WXR(XML)文件,可以检测到对应的用户名了:
Failed to create new user for . Their posts will be attributed to the current user.
All done. Have fun!
Remember to update the passwords and roles of imported users.
【解决过程】
1. 看来是用户名有问题,wordpress的importer无法识别,所以尝试了去修改一下对应的那个againinput4@yeah用户名为againinput_yeah,结果还是同样错误。
2.又试了试,把againinput_yeah改为againinput-yeah,也还是不行。
3. 后来试了试,把againinput-yeah改为againinputyeah,终于可以了。
【总结】
进过这些测试,基本可以推断出根本原因了:
wordpress中,或者至少wordpress的importer中,对于用户名的支持,只支持字母和数字,不支持除了字母,数字,下划线之外的其他字符,包括但不限于短横线’-’,at字符’@’等。
所以,根本原因是:
如果你导入的WXR中用户名
(即的author_login部分,比如<wp:author_login>againinput4@yeah</wp:author_login>中的againinput4@yeah)
中包括了非字母和数字、下划线的字符(即@字符),那么就会出现上述Failed to create new user for的错误。
办法就是,把用户名中非字母和数字、下划线的其他字符过滤掉,就可以了,此处即把againinput4@yeah改为againinput4yeah,即可。
【如何去除字符串中非字母和数字的字符】
对应的python脚本处理的话,只需要一句话就可以了:
newUsername = re.sub(r"[^\w]", "", oldUsername); |
即可把非字母和数字的部分过滤掉了。
如果是其他语言实现的话,自己照葫芦画瓢即可。
【后记】
最新测试发现,如果导入的用户名,已经存在了,那么也会出现同样的错误的。
所以,如果出现此问题,请去 用户 –> 所有用户,看看是不是要导入的用户已经存在了。
而且,如果真的是已经存在了,那么在导入之前:
or assign posts to an existing user: |
的部分,也是可以通过点击Select出现下拉框,找到对应的用户的。
注:
1.后来去把debug打开,则会有对应的debug信息输出的:
Failed to create new user for . Their posts will be attributed to the current user. 该用户名已被注册。 |
2.打开wordpress importer的bug功能的方法:
wp-content\plugins\wordpress-importer\wordpress-importer.php中把
define( ‘IMPORT_DEBUG’, false );
改为:
define( ‘IMPORT_DEBUG’, true );
【总结】
出现“Failed to create new user for . Their posts will be attributed to the current user. ”的错误,目前来说,至少有两种:
原因1:该用户已经存在
办法:可忽略。或者在导入之前,通过“or assign posts to an existing user:”去Select对应的用户即可避免该错误。
原因2:该用户名无效
即用户名中包含了除了字母数字下划线之外的字符,比如我这里的@,-等字符。
办法:确保用户名有效,删除用户名中,非字母数字下划线之外的其他非法字符。
转载请注明:在路上 » 【已解决】使用wordpress importer导入WXR时出错:Failed to create new user for XXX. asign to the current user