変更箇所をメモ
変更箇所
view-import.php
<tr id="row-import-existing-table" class="bottom-border">
<th class="column-1" scope="row"><label for="tables-import-existing-table"><?php _e( 'Table to replace or append to', 'tablepress' ); ?>:</label></th>
<td class="column-2">
<select id="tables-import-existing-table" name="import[existing_table]"<?php disabled( $data['tables_count'] > 0, false, true ); ?>>
<option value=""><?php _e( '— Select —', 'tablepress' ); ?></option>
<?php
$sorted_table_array = array(); // *** add this line ***
foreach ( $data['table_ids'] as $table_id ) {
$table = TablePress::$model_table->load( $table_id, false, false ); // Load table, without table data, options, and visibility settings
if ( ! current_user_can( 'tablepress_edit_table', $table['id'] ) ) {
continue;
}
if ( '' === trim( $table['name'] ) ) {
$table['name'] = __( '(no name)', 'tablepress' );
}
// *** change lines ***
// $text = esc_html( sprintf( __( 'ID %1$s: %2$s', 'tablepress' ), $table['id'], $table['name'] ) );
// $selected = selected( $table['id'], $data['import_existing_table'], false );
// echo "<option{$selected} value=\"{$table['id']}\">{$text}</option>";
// copy to sorted_table
$sorted_table_array[$table['id']] = $table['name'];
}
// *** add lines ***
// sort by name
asort($sorted_table_array, SORT_STRING);
foreach( $sorted_table_array as $id => $name) {
$text = esc_html( sprintf( __( 'ID %1$s: %2$s', 'tablepress' ), $id, $name ) );
$selected = selected( $id, $data['import_existing_table'], false );
echo "<option{$selected} value=\"{$id}\">{$text}</option>";
}
?>
</select>
</td>
</tr>