Make sure WP knows about the payment token meta table, and return null in payment tokens get if a token cannot be found.

This commit is contained in:
Justin Shreve 2016-02-08 11:36:22 -08:00
parent df260c228d
commit 0061b36f3b
2 changed files with 15 additions and 1 deletions

View File

@ -4,6 +4,16 @@ if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* WooCommerce Payment Token Meta API - set table name
*/
function wc_payment_token_metadata_wpdbfix() {
global $wpdb;
$wpdb->payment_tokenmeta = $wpdb->prefix . 'woocommerce_payment_tokenmeta';
$wpdb->tables[] = 'woocommerce_payment_tokenmeta';
}
add_action( 'init', 'wc_payment_token_metadata_wpdbfix', 0 );
/**
* WooCommerce Payment Token
*

View File

@ -91,7 +91,7 @@ class WC_Payment_Tokens {
/**
* Get a token object by ID
* @param int $token_id Token ID
* @return WC_Payment_Token
* @return WC_Payment_Token|null Returns a valid payment token or null if no token can be found
*/
public static function get( $token_id, $token_result = null ) {
global $wpdb;
@ -100,6 +100,10 @@ class WC_Payment_Tokens {
"SELECT * FROM {$wpdb->prefix}woocommerce_payment_tokens WHERE token_id = %d",
$token_id
) );
// Still empty? Token doesn't exist? Don't continue
if ( empty( $token_result) ) {
return null;
}
}
$token_class = 'WC_Payment_Token_' . $token_result->type;
if ( class_exists( $token_class ) ) {