Make WordPress Core

Changeset 32510


Ignore:
Timestamp:
05/19/2015 12:32:10 AM (9 years ago)
Author:
SergeyBiryukov
Message:

Allow wp_dropdown_languages() to return the markup instead of displaying.

props leewillis77, juliobox.
fixes #32432.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/l10n.php

    r31447 r32510  
    852852 *
    853853 * @since 4.0.0
     854 * @since 4.3.0 Introduced the `echo` argument.
    854855 *
    855856 * @see get_available_languages()
     
    859860 *     Optional. Array or string of arguments for outputting the language selector.
    860861 *
    861  *     @type string  $id                           ID attribute of the select element. Default empty.
    862  *     @type string  $name                         Name attribute of the select element. Default empty.
    863  *     @type array   $languages                    List of installed languages, contain only the locales.
    864  *                                                 Default empty array.
    865  *     @type array   $translations                 List of available translations. Default result of
    866  *                                                 {@see wp_get_available_translations()}.
    867  *     @type string  $selected                     Language which should be selected. Default empty.
    868  *     @type bool    $show_available_translations  Whether to show available translations. Default true.
     862 *     @type string   $id                           ID attribute of the select element. Default empty.
     863 *     @type string   $name                         Name attribute of the select element. Default empty.
     864 *     @type array    $languages                    List of installed languages, contain only the locales.
     865 *                                                  Default empty array.
     866 *     @type array    $translations                 List of available translations. Default result of
     867 *                                                  {@see wp_get_available_translations()}.
     868 *     @type string   $selected                     Language which should be selected. Default empty.
     869 *     @type bool|int $echo                         Whether to echo or return the generated markup. Accepts 0, 1, or their
     870 *                                                  bool equivalents. Default 1.
     871 *     @type bool     $show_available_translations  Whether to show available translations. Default true.
    869872 * }
     873 * @return string HTML content only if 'echo' argument is 0.
    870874 */
    871875function wp_dropdown_languages( $args = array() ) {
     
    877881        'translations' => array(),
    878882        'selected'     => '',
     883        'echo'         => 1,
    879884        'show_available_translations' => true,
    880885    ) );
     
    913918    $translations_available = ( ! empty( $translations ) && $args['show_available_translations'] );
    914919
    915     printf( '<select name="%s" id="%s">', esc_attr( $args['name'] ), esc_attr( $args['id'] ) );
     920    $output = sprintf( '<select name="%s" id="%s">', esc_attr( $args['name'] ), esc_attr( $args['id'] ) );
    916921
    917922    // Holds the HTML markup.
     
    951956    }
    952957
    953     echo join( "\n", $structure );
    954 
    955     echo '</select>';
    956 }
     958    $output .= join( "\n", $structure );
     959
     960    $output .= '</select>';
     961
     962    if ( $args['echo'] ) {
     963        echo $output;
     964    }
     965
     966    return $output;
     967}
Note: See TracChangeset for help on using the changeset viewer.