maybe_add_column( string $table_name, string $column_name, string $create_ddl ): bool
- Since
- 1.3.0
- Source
wp-admin/includes/upgrade.php:2764
Adds column to a database table, if it doesn't already exist.
Parameters
$table_namestring- Database table name.
$column_namestring- Table column name.
$create_ddlstring- SQL statement to add column.
Return
bool- True on success or if the column already exists. False on failure.
Source
function maybe_add_column( $table_name, $column_name, $create_ddl ) { global $wpdb; foreach ( $wpdb->get_col( "DESC $table_name", 0 ) as $column ) { if ( $column === $column_name ) { return true; } } // Didn't find it, so try to create it. $wpdb->query( $create_ddl ); // We cannot directly tell that whether this succeeded! foreach ( $wpdb->get_col( "DESC $table_name", 0 ) as $column ) { if ( $column === $column_name ) { return true; } } return false;}History
Introduced in 1.3.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-admin/includes/upgrade.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it. - Corrections
- Something wrong on this page? Report it and it gets fixed in the next regeneration.