一個插件爲WordPress多站點網絡提供登錄。此插件現在在WP 3.5下失敗,因爲user.php文件已更改。 /wp-includes/user.php中的舊行可以重新添加,插件可以工作。顯然這不是一個長期的解決方案。WordPress 3.5更改User.php哪個打破插件,這個功能可以成爲問題?它可以修復嗎?
這是user.php的
if (empty($user))
$user = wp_get_current_user();
else
$user = new WP_User($user);
if (! isset($user->ID))
return false;
舊的代碼是從3.5
if (empty($user))
$user = get_current_user_id();
if (! $user = get_userdata($user))
return false;
新的代碼,我努力學習PHP初學者,所以我不知道在所有的意義上。但是,我認爲這是插件中的代碼導致問題:
function get_userdata($ user_id){ global $ wpdb;
if (! is_numeric($user_id))
return false;
$user_id = absint($user_id);
if (! $user_id)
return false;
$user = wp_cache_get($user_id, 'users'); //check to see if the cache object already has the user
if ($user)
{
return $user; //it was in the cache
}
$user = new StdClass();
global $XF;
XF_User_Data::fillUserData($XF->visitor, $user, $user_id);
update_user_caches($user);
return $user;
}
新的一個StdClass可以被註釋掉,除去錯誤,但當時沒有人可以登錄。
我該如何重寫這個函數來避免錯誤?
*致命錯誤:調用未定義的方法stdClass的:: has_prop()/wp-includes/user.php*
插件的開發商是「度假」,並沒有更新。他正在等待其他一些更改,但是,這需要修復。
關於修復代碼的任何建議?我看錯了地方?在有人能幫忙之前需要其他細節嗎?
你看過:http://codex.wordpress.org/Function_Reference/get_userdata可能會給你一些提示如何正確調用get_userdata。 –
謝謝。我只是更新/使用插件的功能,並看到get_userdata。我可以將$ user = new StdClass註釋掉,但是沒有人可以登錄。我更新了原文,在他的插件中顯示了代碼。 – LPH
將新的StdClass行更改爲$ user = new WP_User($ user)似乎修復了錯誤並允許用戶登錄。 – LPH