Making WordPress.org

Changeset 9838


Ignore:
Timestamp:
05/09/2020 04:05:35 PM (4 years ago)
Author:
ocean90
Message:

Rosetta: Add dropdown with available locales for locale associations.

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/rosetta/inc/admin/network
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/rosetta/inc/admin/network/class-locale-associations-view.php

    r8430 r9838  
    119119            <p>
    120120                <label for="locale"><?php _e( 'Locale:', 'rosetta' ); ?></label>
    121                 <input type="text" id="locale" name="locale" class="code" />
     121                <select id="locale" name="locale" required>
     122                    <option value=""><?php _e( '&mdash; Select &mdash;', 'rosetta' ); ?></option>
     123                    <?php
     124                    foreach ( $this->page->get_available_wp_locales() as $locale ) {
     125                        printf(
     126                            '<option value="%s">%s</option>',
     127                            esc_attr( $locale ),
     128                            esc_html( $locale )
     129                        );
     130                    }
     131                    ?>
     132                </select>
    122133
    123134                <label for="subdomain"><?php _e( 'Subdomain:', 'rosetta' ); ?></label>
    124                 <input type="text" id="subdomain" name="subdomain" class="code" />
     135                <input type="text" id="subdomain" name="subdomain" class="code" required />
    125136            </p>
    126137
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/rosetta/inc/admin/network/class-locale-associations.php

    r8430 r9838  
    33namespace WordPressdotorg\Rosetta\Admin\Network;
    44
     5use GP_Locales;
    56use WordPressdotorg\Rosetta\Admin\Admin_Page;
    67use WordPressdotorg\Rosetta\Admin\Admin_Page_View;
     
    224225
    225226    /**
     227     * Retrieves all available WP locales which are not assigned to a site yet.
     228     *
     229     * @return array List of locales.
     230     */
     231    public function get_available_wp_locales() {
     232        global $wpdb;
     233
     234        $locales           = GP_Locales::locales();
     235        $wp_locales        = array_filter( wp_list_pluck( $locales, 'wp_locale' ) );
     236        $wp_locales_in_use = $wpdb->get_col( 'SELECT locale FROM ' . Tables::LOCALES );
     237
     238        $wp_locales_in_use[] = 'en_US';
     239
     240        return array_diff( $wp_locales, $wp_locales_in_use );
     241    }
     242
     243    /**
    226244     * Gets the admin URL of the page.
    227245     *
Note: See TracChangeset for help on using the changeset viewer.