Make WordPress Core

Ticket #32432: 32432.2.diff

File 32432.2.diff, 2.2 KB (added by leewillis77, 11 years ago)

Revised patch. Introduces get_dropdown_languages(). Makes wp_dropdown_languages() use this to do the heavy lifting.

  • wp-includes/l10n.php

     
    852852 *
    853853 * @since 4.0.0
    854854 *
     855 * @see get_dropdown_languages()
    855856 * @see get_available_languages()
    856857 * @see wp_get_available_translations()
    857858 *
     
    869870 * }
    870871 */
    871872function wp_dropdown_languages( $args = array() ) {
     873        echo get_dropdown_languages( $args );
     874}
    872875
     876/**
     877 * Generates the markup of the language selector.
     878 *
     879 * @since 4.3
     880 *
     881 * @see get_available_languages()
     882 * @see wp_get_available_translations()
     883 *
     884 * @param string|array $args {
     885 *     Optional. Array or string of arguments for creating the language selector.
     886 *
     887 *     @type string  $id                           ID attribute of the select element. Default empty.
     888 *     @type string  $name                         Name attribute of the select element. Default empty.
     889 *     @type array   $languages                    List of installed languages, contain only the locales.
     890 *                                                 Default empty array.
     891 *     @type array   $translations                 List of available translations. Default result of
     892 *                                                 {@see wp_get_available_translations()}.
     893 *     @type string  $selected                     Language which should be selected. Default empty.
     894 *     @type bool    $show_available_translations  Whether to show available translations. Default true.
     895 * }
     896 */
     897function get_dropdown_languages( $args = array() ) {
     898        $markup = '';
    873899        $args = wp_parse_args( $args, array(
    874900                'id'           => '',
    875901                'name'         => '',
     
    912938
    913939        $translations_available = ( ! empty( $translations ) && $args['show_available_translations'] );
    914940
    915         printf( '<select name="%s" id="%s">', esc_attr( $args['name'] ), esc_attr( $args['id'] ) );
     941        $markup .= sprintf( '<select name="%s" id="%s">', esc_attr( $args['name'] ), esc_attr( $args['id'] ) );
    916942
    917943        // Holds the HTML markup.
    918944        $structure = array();
     
    949975                }
    950976                $structure[] = '</optgroup>';
    951977        }
    952 
    953         echo join( "\n", $structure );
    954 
    955         echo '</select>';
     978        $markup .= join( "\n", $structure );
     979        $markup .= '</select>';
     980        return $markup;
    956981}