Last active
May 22, 2021 00:20
-
-
Save devuri/cc896dc664f53c29d265c01c9dd6eca6 to your computer and use it in GitHub Desktop.
How to Retrieve a list of database table names for WordPress Database
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace MyPlugin\Database; | |
class WPTable | |
{ | |
/** | |
* Get wp database tables. | |
* | |
* @return object | |
*/ | |
protected static function tables() { | |
global $wpdb; | |
return $wpdb->get_results( | |
$wpdb->prepare( "SHOW TABLES" ) | |
); | |
} | |
/** | |
* Get the tables list. | |
* | |
* @return array . | |
*/ | |
public static function table_list() { | |
foreach ( self::tables() as $get_tables ) { | |
foreach ( $get_tables as $table ) { | |
$list[] = $table; | |
} | |
} | |
return $list; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment