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 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题