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 Stata链式中介效应代码修改
  • ¥15 latex投稿显示click download
  • ¥15 请问读取环境变量文件失败是什么原因?
  • ¥15 在若依框架下实现人脸识别
  • ¥15 添加组件无法加载页面,某块加载卡住
  • ¥15 网络科学导论,网络控制
  • ¥100 安卓tv程序连接SQLSERVER2008问题
  • ¥15 利用Sentinel-2和Landsat8做一个水库的长时序NDVI的对比,为什么Snetinel-2计算的结果最小值特别小,而Lansat8就很平均
  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用