LoginSignup
0

More than 5 years have passed since last update.

TablePress importのテーブル選択フォームの並び順変更

Posted at

変更箇所をメモ

変更箇所

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( '&mdash; Select &mdash;', '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>

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0