Making WordPress.org


Ignore:
Timestamp:
09/03/2020 11:57:12 PM (3 years ago)
Author:
coreymckrill
Message:

WordPress.org Learn: Sync with GitHub

https://github.com/WordPress/learn/compare/fcab3279c24740fb625278be5fd3484157df8941...81fc947c7f4f4174ef30a2f6c9fc42d3608e5a49

Location:
sites/trunk/wordpress.org/public_html/wp-content/mu-plugins
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/mu-plugins

    • Property svn:ignore set to
      0-sandbox.php
  • sites/trunk/wordpress.org/public_html/wp-content/mu-plugins/pub/locales.php

    r8347 r10237  
    1212namespace WordPressdotorg\Locales {
    1313
    14     use GP_Locales;
     14    use GP_Locales, GP_Locale;
    1515
    1616    /**
     
    2929    }
    3030    add_filter( 'get_available_languages', __NAMESPACE__ . '\set_available_languages', 10, 0 );
     31
     32    /**
     33     * Retrieves all available locales.
     34     *
     35     * @return GP_Locale[] Array of locale objects.
     36     */
     37    function get_locales() {
     38        wp_cache_add_global_groups( array( 'locale-associations' ) );
     39
     40        $wp_locales = wp_cache_get( 'locale-list', 'locale-associations' );
     41        if ( false === $wp_locales ) {
     42            $wp_locales = (array) $GLOBALS['wpdb']->get_col( 'SELECT locale FROM wporg_locales' );
     43            wp_cache_set( 'locale-list', $wp_locales, 'locale-associations' );
     44        }
     45
     46        $wp_locales[] = 'en_US';
     47        $locales = array();
     48
     49        foreach ( $wp_locales as $locale ) {
     50            $gp_locale = GP_Locales::by_field( 'wp_locale', $locale );
     51            if ( ! $gp_locale ) {
     52                continue;
     53            }
     54
     55            $locales[ $locale ] = $gp_locale;
     56        }
     57
     58        natsort( $locales );
     59
     60        return $locales;
     61    }
     62
     63    /**
     64     * Get an array of locales with the locale code as key and the native name as value.
     65     *
     66     * @return array
     67     */
     68    function get_locales_with_native_names() {
     69        $locales = get_locales();
     70
     71        return wp_list_pluck( $locales, 'native_name', 'wp_locale' );
     72    }
     73
     74    /**
     75     * Get an array of locales with the locale code as key and the English name as value.
     76     *
     77     * @return array
     78     */
     79    function get_locales_with_english_names() {
     80        $locales = get_locales();
     81
     82        return wp_list_pluck( $locales, 'english_name', 'wp_locale' );
     83    }
    3184}
Note: See TracChangeset for help on using the changeset viewer.