
WordPress代码生成器如何加快开发速度
check_column ( $table_name, $col_name, $col_type, $is_null = null, $key = null, $default_value = null, $extra = null )
check_column: 这个函数检查一个列是否支持特定的屏幕或文章类型。它被WordPress的管理屏幕使用,以确定在一个特定的屏幕上应该显示哪些列。
检查数据库表列是否符合标准。
使用SQL DESC来检索该列的表信息。如果你对SQL语句返回的列信息做更多的研究,这将有助于理解参数。传入null以跳过检查该标准。
从DESC表返回的列名是区分大小写的,并被列出。
Field
Type
Null
Key
Default
Extra
function check_column( $table_name, $col_name, $col_type, $is_null = null, $key = null, $default_value = null, $extra = null ) { global $wpdb; $diffs = 0; $results = $wpdb->get_results( "DESC $table_name" ); foreach ( $results as $row ) { if ( $row->Field === $col_name ) { // Got our column, check the params. if ( ( null !== $col_type ) && ( $row->Type !== $col_type ) ) { ++$diffs; } if ( ( null !== $is_null ) && ( $row->Null !== $is_null ) ) { ++$diffs; } if ( ( null !== $key ) && ( $row->Key !== $key ) ) { ++$diffs; } if ( ( null !== $default_value ) && ( $row->Default !== $default_value ) ) { ++$diffs; } if ( ( null !== $extra ) && ( $row->Extra !== $extra ) ) { ++$diffs; } if ( $diffs > 0 ) { return false; } return true; } // End if found our column. } return false; }