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条)

报告相同问题?