maybe_drop_column
Drop column from database table, if it exists.
Description
Parameters (3)
- 0. $table_name (string)
- The table name.
- 1. $column_name (string)
- The column name.
- 2. $drop_ddl (string)
- SQL statement to drop column.
Usage
if ( !function_exists( 'maybe_drop_column' ) ) { require_once ABSPATH . '/wp-admin/install-helper.php'; } // The table name. $table_name = ''; // The column name. $column_name = ''; // SQL statement to drop column. $drop_ddl = ''; // NOTICE! Understand what this does before running. $result = maybe_drop_column($table_name, $column_name, $drop_ddl);
Defined (1)
The function is defined in the following location(s).
- /wp-admin/install-helper.php
- function maybe_drop_column($table_name, $column_name, $drop_ddl) {
- global $wpdb;
- foreach ($wpdb->get_col("DESC $table_name", 0) as $column ) {
- if ($column == $column_name) {
- // Found it, so try to drop it.
- $wpdb->query($drop_ddl);
- // We cannot directly tell that whether this succeeded!
- foreach ($wpdb->get_col("DESC $table_name", 0) as $column ) {
- if ($column == $column_name) {
- return false;
- }
- }
- }
- }
- // Else didn't find it.
- return true;
- }