Merge pull request #19436 from liquidweb/feature/register-additional-woocommerce-tables

Add the "woocommerce_install_get_tables" filter to WC_Install::get_tables()
This commit is contained in:
Mike Jolley 2018-03-19 12:50:40 +00:00 committed by GitHub
commit 127b9a89d0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 0 deletions

View File

@ -780,6 +780,15 @@ CREATE TABLE {$wpdb->prefix}woocommerce_termmeta (
$tables[] = "{$wpdb->prefix}woocommerce_termmeta";
}
/**
* Filter the list of known WooCommerce tables.
*
* If WooCommerce plugins need to add new tables, they can inject them here.
*
* @param array $tables An array of WooCommerce-specific database table names.
*/
$tables = apply_filters( 'woocommerce_install_get_tables', $tables );
return $tables;
}

View File

@ -125,4 +125,25 @@ class WC_Tests_Install extends WC_Unit_Test_Case {
$this->assertEquals( $tables, WC_Install::get_tables() );
}
/**
* Test - get tables should apply the woocommerce_install_get_tables filter.
*/
public function test_get_tables_enables_filter() {
$default = WC_Install::get_tables();
$added = $this->append_table_to_get_tables( array() );
add_filter( 'woocommerce_install_get_tables', array( $this, 'append_table_to_get_tables' ) );
$this->assertEquals( $added, array_values( array_diff( WC_Install::get_tables(), $default ) ) );
}
/**
* Filter callback for test_get_tables_enables_filter().
*/
public function append_table_to_get_tables( $tables ) {
$tables[] = 'some_table_name';
return $tables;
}
}