Merge pull request #23529 from woocommerce/update/23512

Define $wpdb tables as early as possible, before init
This commit is contained in:
Gerhard Potgieter 2019-05-10 10:38:15 +02:00 committed by GitHub
commit 81bfb9cacb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 21 additions and 11 deletions

View File

@ -152,6 +152,7 @@ final class WooCommerce {
*/
public function __construct() {
$this->define_constants();
$this->define_tables();
$this->includes();
$this->init_hooks();
}
@ -184,7 +185,6 @@ final class WooCommerce {
add_action( 'init', array( $this, 'init' ), 0 );
add_action( 'init', array( 'WC_Shortcodes', 'init' ) );
add_action( 'init', array( 'WC_Emails', 'init_transactional_emails' ) );
add_action( 'init', array( $this, 'wpdb_table_fix' ), 0 );
add_action( 'init', array( $this, 'add_image_sizes' ) );
add_action( 'switch_blog', array( $this, 'wpdb_table_fix' ), 0 );
add_action( 'activated_plugin', array( $this, 'activated_plugin' ) );
@ -230,6 +230,25 @@ final class WooCommerce {
$this->define( 'WC_TEMPLATE_DEBUG_MODE', false );
}
/**
* Register custom tables within $wpdb object.
*/
private function define_tables() {
global $wpdb;
// List of tables without prefixes.
$tables = array(
'payment_tokenmeta' => 'woocommerce_payment_tokenmeta',
'order_itemmeta' => 'woocommerce_order_itemmeta',
'wc_product_meta_lookup' => 'wc_product_meta_lookup',
);
foreach ( $tables as $name => $table ) {
$wpdb->$name = $wpdb->prefix . $table;
$wpdb->tables[] = $table;
}
}
/**
* Define constant if not already set.
*
@ -710,16 +729,7 @@ final class WooCommerce {
* Set tablenames inside WPDB object.
*/
public function wpdb_table_fix() {
global $wpdb;
$wpdb->payment_tokenmeta = $wpdb->prefix . 'woocommerce_payment_tokenmeta';
$wpdb->tables[] = 'woocommerce_payment_tokenmeta';
$wpdb->order_itemmeta = $wpdb->prefix . 'woocommerce_order_itemmeta';
$wpdb->tables[] = 'woocommerce_order_itemmeta';
$wpdb->wc_product_meta_lookup = $wpdb->prefix . 'wc_product_meta_lookup';
$wpdb->tables[] = 'wc_product_meta_lookup';
$this->define_tables();
}
/**