
如何实现WordPress网站降级(用于解决插件和主题问题)
maybe_add_column ( $table_name, $column_name, $create_ddl )
maybe_add_column: 这是WordPress中的一个函数,允许你在数据库表中添加一个列,如果它还不存在的话: 这个函数检查一个列是否存在于指定的表中,如果不存在,它就把这个列添加到表中。
为数据库表添加列,如果它还不存在的话。
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; } endif; /** * Drops column from database table, if it exists. * * @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 $drop_ddl SQL statement to drop column. * @return bool True on success or if the column doesn't exist. False on failure. */