[英]Getting error in WordPress Illegal string offset
PHP Warning: Illegal string offset 'user_login' in /home/.../wp-includes/user.php on line 83
PHP Warning: Illegal string offset 'user_password' in /home/.../wp-includes/user.php on line 83
这里的代码:-
add_filter('authenticate', 'wp_authenticate_cookie', 30, 3);
$user = wp_authenticate($credentials['user_login'], $credentials['user_password']);
if ( is_wp_error($user) ) {
if ( $user->get_error_codes() == array('empty_username', 'empty_password') ) {
$user = new WP_Error('', '');
}
return $user;
}
显然$credentials
不是那个数组。 显示var_dump($credentials);
错误字符串偏移量'whatever'in ...通常意味着:您正在尝试将字符串用作完整数组。
实际上这是可能的,因为在PHP中,字符串可以被视为单个字符的数组。 所以您认为$ var是带有键的数组,但是它只是具有标准数字键的字符串
尝试在$ user之前添加以下行
if(isset($_POST)){ $credentials = array( 'user_login' => isset($_POST['log']) ? $_POST['log'] : '', 'user_password' => isset($_POST['pwd']) ? $_POST['pwd'] :'', ); }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.