dongliang1654
2018-06-01 09:42
浏览 87
已采纳

错误的字符集get_error_message()wordpress

There is PHP method in my API for handling POST requests:

...

$user_id = wp_create_user( $user_login, $user_pass, $user_login );

if ( is_wp_error( $user_id ) ) {
    $base_response['message'] = $user_id->get_error_message();
    $base_response['status'] = false;
    return json_encode ($base_response);
}

...

If user already exists, I get error message, but why this message ($base_response['message']) has unicode format: "u041du0430 u0436u0430u043bu044c, u0446u0435 u0456u043c'u044f u043au043eu0440u0438u0441u0442u0443u0432u0430u0447u0430 u0432u0436u0435 u0456u0441u043du0443u0454!". How to change this?

图片转代码服务由CSDN问答提供 功能建议

我的API中有用于处理POST请求的PHP方法:

 <  code> ... 
 
 $ user_id = wp_create_user($ user_login,$ user_pass,$ user_login); 
 
if(is_wp_error($ user_id)){
 $ base_response ['message'] = $ user_id-&gt  ; get_error_message(); 
 $ base_response ['status'] = false; 
返回json_encode($ base_response); 
} 
 
 ... 
   
 
  

如果用户已经存在,我收到错误消息,但为什么此消息($ base_response ['message'])具有unicode格式:“u041du0430 u0436u0430u043bu044c,u0446u0435 u0456u043c'u044f u043au043eu0440u0438u0441u0442u0443u0432u0430u0447u0430 u0432u0436u0435 u0456u0441u043du0443u0454!”。 如何改变这个?

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dqthn68688 2018-06-01 10:16
    已采纳

    The problem was in cyrillic language for wordpress site and json_encode could not correctly convert cyrillic message. When I changed the language in the wordpress admin to English, everything is fine now.

    已采纳该答案
    打赏 评论
  • doq13207 2018-06-01 09:51

    You have wrong parameter in wp_create_user function. You need to pass Email in last parameter instead of user_login .

    $user_id = wp_create_user( $user_login, $user_pass, $user_email );
    
    if ( is_wp_error( $user_id ) ) {
        $base_response['message'] = $user_id->get_error_message();
        $base_response['status'] = false;
        return json_encode ($base_response);
    }
    

    Refer document for correct parameter : https://developer.wordpress.org/reference/functions/wp_create_user/

    打赏 评论

相关推荐 更多相似问题