wpseek.com
A WordPress-centric search engine for devs and theme authors
maybe_create_table › WordPress Function
Since1.0.0
Deprecatedn/a
› maybe_create_table ( $table_name, $create_ddl )
Parameters: (2) |
|
Returns: |
|
Defined at: |
|
Codex: |
Creates a table in the database if it doesn't already exist.
Related Functions: _oembed_create_xml, wp_create_tag, wpmu_create_blog, maybe_convert_table_to_utf8mb4, _maybe_update_themes
Source
function maybe_create_table( $table_name, $create_ddl ) {
global $wpdb;
foreach ( $wpdb->get_col( 'SHOW TABLES', 0 ) as $table ) {
if ( $table === $table_name ) {
return true;
}
}
// Didn't find it, so try to create it.
// phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared -- No applicable variables for this query.
$wpdb->query( $create_ddl );
// We cannot directly tell whether this succeeded!
foreach ( $wpdb->get_col( 'SHOW TABLES', 0 ) as $table ) {
if ( $table === $table_name ) {
return true;
}
}
return false;
}
endif;
if ( ! function_exists( 'maybe_add_column' ) ) :
/**
* Adds column to database table, if it doesn't already exist.
*
* @since 1.0.0
*
* @global wpdb $wpdb WordPress database abstraction object.
*
* @param string $table_name Database table name.
* @param string $column_name Table column name.
* @param string $create_ddl SQL statement to add column.
* @return bool True on success or if the column already exists. False on failure.
*/