嘗試在某人登錄WordPress後訪問插件中的用戶標識,以便我可以將他們在會話中執行的操作分配給自定義表中的該用戶標識。嘗試在WordPress登錄後訪問用戶ID
我有這樣的:
add_action('wp_authenticate', 'orr_gamify_save_session_to_user');
我也想嘗試:
add_action('wp_login', 'orr_gamify_save_session_to_user');
但是,這也不能工作。
然後函數是:
function orr_gamify_save_session_to_user() {
global $wpdb,$current_user;
if(!session_id())
{
session_start();
}
$UserID = $DataToUpdate[UserID] = get_current_user_id();
$SessionID = $WhereToUpdate[SessionID] = session_id();
$TableName = "wp_gamify";
if($UserID != 0)
{
if($wpdb->update($TableName,$DataToUpdate,$WhereToUpdate))
{
#print '<div class="alert alert-success fade in"><strong>Attempting...</strong> User '.$UserID.' for Sesssion '.$SessionID.'</div>';
#print '<div class="alert alert-success fade in"><strong>Success!</strong> We\'ve assigned your progress to your account.</div>';
}
else
{
#print '<div class="alert alert-danger fade in"><strong>Failed!</strong> We were unable to save your progress to your account.</div>';
}
}
}
它更新,但它給了我零用戶名。
所以你的函數get被觸發了,數據庫得到了更新,但是變量UserID = 0? – TeeDeJee