在Wordpress上登录后尝试访问用户ID

时间:2015-08-24 13:44:39

标签: php wordpress-plugin wordpress

在有人登录WordPress后尝试访问插件中的userid,以便我可以将他们在会话中所执行的操作分配给自定义表中的该用户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>';
            }
        }
}

它更新,但它给了我一个零的UserID。

0 个答案:

没有答案