最近将环境升级到PHP 7,发现WordPress后台打开空白,开启详细报错后提示wp-includes/user.php
这个文件有异常。php
也不知道是否自己WordPress版本(4.3)较低的原因,可以参考如下方法解决。修改wp-includes/user.php
这个文件,在
if ( empty($credentials) ) {
后面增加:
$credentials = array(); // 增加这行代码
增加完成后的代码如下,保存后正常。
function wp_signon( $credentials = array(), $secure_cookie = '' ) {
if ( empty($credentials) ) {
$credentials = array(); // Back-compat for plugins passing an empty string.
if ( ! empty($_POST['log']) )
$credentials['user_login'] = $_POST['log'];
if ( ! empty($_POST['pwd']) )
$credentials['user_password'] = $_POST['pwd'];
if ( ! empty($_POST['rememberme']) )
$credentials['remember'] = $_POST['rememberme'];
}
if ( !empty($credentials['remember']) )
$credentials['remember'] = true;
else
$credentials['remember'] = false;
/**
* Fires before the user is authenticated.
*
* The variables passed to the callbacks are passed by reference,
* and can be modified by callback functions.
*
* @since 1.5.1
*
* @todo Decide whether to deprecate the wp_authenticate action.
*
* @param string $user_login Username, passed by reference.
* @param string $user_password User password, passed by reference.
*/
do_action_ref_array( 'wp_authenticate', array( &$credentials['user_login'], &$credentials['user_password'] ) );
if ( '' === $secure_cookie )
$secure_cookie = is_ssl();
/**
* Filters whether to use a secure sign-on cookie.
*
* @since 3.1.0
*
* @param bool $secure_cookie Whether to use a secure sign-on cookie.
* @param array $credentials {
* Array of entered sign-on data.
*
* @type string $user_login Username.
* @type string $user_password Password entered.
* @type bool $remember Whether to 'remember' the user. Increases the time
* that the cookie will be kept. Default false.
* }
*/
$secure_cookie = apply_filters( 'secure_signon_cookie', $secure_cookie, $credentials );
global $auth_secure_cookie; // XXX ugly hack to pass this to wp_authenticate_cookie
$auth_secure_cookie = $secure_cookie;
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;
}
wp_set_auth_cookie($user->ID, $credentials['remember'], $secure_cookie);
/**
* Fires after the user has successfully logged in.
*
* @since 1.5.0
*
* @param string $user_login Username.
* @param WP_User $user WP_User object of the logged-in user.
*/
do_action( 'wp_login', $user->user_login, $user );
return $user;
}
此文参考了:PHP7.1环境中,WordPress登录失败
应该是wordpress版本太低的问题。
阿里云 Centos 7 64位,PHP 7.0.8 wordpress 4.7没问题
可能是的,后来我也升级了wp版本。
PHP的站点好是好,就是用的时候经常莫名其妙的出问题,不如asp好用,小站还是建议用asp写的源码好!
相反,个人觉得PHP更加成熟稳定。