简体   繁体   中英

Not getting logged-in user id in Wordpress 3.4

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.

Try this,

global $current_user;
get_currentuserinfo();
$log_user_id = $current_user->ID;

You may use like , sometime we get some syntax error spell mistakes:

reference

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM