maybe_drop_column

函数
maybe_drop_column ( $table_name, $column_name, $drop_ddl )
参数
  • (string) $table_name Database table name.
    Required:
  • (string) $column_name Table column name.
    Required:
  • (string) $drop_ddl SQL statement to drop column.
    Required:
返回值
  • (bool) True on success or if the column doesn't exist. False on failure.
定义位置
相关方法
maybe_add_column_maybe_update_plugins_maybe_update_coreget_hidden_columnsparent_dropdown
引入
1.0.0
弃用
-

maybe_drop_column: 这是WordPress中的一个函数,允许你从数据库表中删除一个列,如果它存在的话: 这个函数检查该列是否存在,如果存在,它就把该列从表中删除。

从数据库表中删除列,如果它存在的话。

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;
}

常见问题

FAQs
查看更多 >
闪电侠

(工作日 10:00 - 18:30 为您服务)

2025-12-14 23:36:43

您好,无论是售前、售后、意见建议……均可通过联系工单与我们取得联系。

您也可选择聊天工具与我们即时沟通或点击查看:

您的工单我们已经收到,我们将会尽快跟您联系!
取消
选择聊天工具: