droc60607 2012-12-25 11:54
浏览 31
已采纳

未在Wordpress 3.4中登录用户ID

I am using a Paypal plugin and modifying that as per my requirements. For that I want to get the user id of the current user on the payment.php page; I have tried various functions such as wp_get_current_user(), is_logged_in(), get_current_user_id() etc but I am not getting the user id in payment page.

I am getting the user id on other pages.

Below is the code of payment page

public static function insert_payment( $data, $transaction_id = 0 ) {
        global $wpdb;

        $sql = "SELECT transaction_id
                FROM " . $wpdb->prefix . "wpuf_transaction
                WHERE transaction_id = '" . $wpdb->escape( wpuf_clean_tags( $transaction_id ) ) . "' LIMIT 1";

        $result = $wpdb->get_row( $sql );
        $tran = $wpdb->escape( wpuf_clean_tags( $transaction_id ) );
    if($tran !="")
    {

        if ( !$result ) 
        {
                $log_user_id=get_current_user_id(); // Not Getting user id here
                $log_user_id = $data['user_id'];
                $find_user_id = $wpdb->get_row("SELECT user_id FROM " . $wpdb->prefix . "wpuf_transaction WHERE user_id=".$log_user_id);                
                $find_user_id123 =  $find_user_id->user_id;
                if($find_user_id123=='')
                {
                    $wpdb->insert( $wpdb->prefix . 'wpuf_transaction', $data );
                    do_action( 'wpuf_payment_received', $data );
                }
                else
                {
                     $wpdb->update( $wpdb->prefix . 'wpuf_transaction', $data, array('user_id' => $log_user_id) );
                }
        }

}
}

Any help will be appreciated; thanks in Advance.

  • 写回答

2条回答 默认 最新

  • dongmeiba6151 2012-12-25 11:58
    关注

    Try this,

    global $current_user;
    get_currentuserinfo();
    $log_user_id = $current_user->ID;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 maccms影视模板 制作影视网站失败 求
  • ¥15 stm32按键设置闹钟数进退位不正常
  • ¥15 三电平逆变器中点电位平衡问题
  • ¥20 这怎么写啊 java课设
  • ¥15 用C语言完成一个复杂的游戏
  • ¥15 如何批量更改很多个文件夹里的文件名中包含文件夹名?
  • ¥50 MTK手机模拟HID鼠标出现卡顿
  • ¥20 求下下面这个数据结构代码
  • ¥20 前端 二进制文件流图片转化异常
  • ¥15 github上的这个C语言项目如何跑起来