【问题标题】:Getting error in WordPress Illegal string offset在 WordPress 非法字符串偏移中出现错误
【发布时间】:2019-02-20 05:48:48
【问题描述】:
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;
}

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

    显然$credentials 不是那个数组。显示var_dump($credentials);

    错误 Illegal string offset 'whatever' in... 通常意味着:您正在尝试将字符串用作完整数组。

    这实际上是可能的,因为字符串在 PHP 中可以被视为单个字符的数组。所以你认为 $var 是一个带有键的数组,但它只是一个带有标准数字键的字符串

    【讨论】:

      【解决方案2】:
      • 尝试在 $ user 之前添加以下行

             if(isset($_POST)){                                         
                 $credentials = array(                               
                    'user_login' => isset($_POST['log']) ? $_POST['log'] : '',
                    'user_password' => isset($_POST['pwd']) ? $_POST['pwd'] :'',                  
                );                                                              
             }
        

      【讨论】:

      • 添加此代码后,每当我登录 wp-admin 时,它都会打开主站点而不是仪表板。
      • 您的问题解决了吗?你的仪表板工作与否?
      • 你能告诉我你使用的wordpress版本吗?
      • WordPress 版本 4.5.2
      • 我已经下载了wordpress 4.5.2版我找不到问题,但我认为它一定与您使用的php版本有关尝试yoursite.com/readme.html在那里您可以找到系统要求它说您必须至少具有 5.2.4 的 php 版本,您还可以查看建议。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多