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

props leewillis77, juliobox.
fixes #32432.
Built from https://develop.svn.wordpress.org/trunk@32510


git-svn-id: http://core.svn.wordpress.org/trunk@32480 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Sergey Biryukov 2015-05-19 00:33:26 +00:00
parent 348ec03052
commit d40fe7d80b
2 changed files with 23 additions and 12 deletions

View File

@ -851,6 +851,7 @@ function wp_get_pomo_file_data( $po_file ) {
* Language selector.
*
* @since 4.0.0
* @since 4.3.0 Introduced the `echo` argument.
*
* @see get_available_languages()
* @see wp_get_available_translations()
@ -858,15 +859,18 @@ function wp_get_pomo_file_data( $po_file ) {
* @param string|array $args {
* Optional. Array or string of arguments for outputting the language selector.
*
* @type string $id ID attribute of the select element. Default empty.
* @type string $name Name attribute of the select element. Default empty.
* @type array $languages List of installed languages, contain only the locales.
* Default empty array.
* @type array $translations List of available translations. Default result of
* {@see wp_get_available_translations()}.
* @type string $selected Language which should be selected. Default empty.
* @type bool $show_available_translations Whether to show available translations. Default true.
* @type string $id ID attribute of the select element. Default empty.
* @type string $name Name attribute of the select element. Default empty.
* @type array $languages List of installed languages, contain only the locales.
* Default empty array.
* @type array $translations List of available translations. Default result of
* {@see wp_get_available_translations()}.
* @type string $selected Language which should be selected. Default empty.
* @type bool|int $echo Whether to echo or return the generated markup. Accepts 0, 1, or their
* bool equivalents. Default 1.
* @type bool $show_available_translations Whether to show available translations. Default true.
* }
* @return string HTML content only if 'echo' argument is 0.
*/
function wp_dropdown_languages( $args = array() ) {
@ -876,6 +880,7 @@ function wp_dropdown_languages( $args = array() ) {
'languages' => array(),
'translations' => array(),
'selected' => '',
'echo' => 1,
'show_available_translations' => true,
) );
@ -912,7 +917,7 @@ function wp_dropdown_languages( $args = array() ) {
$translations_available = ( ! empty( $translations ) && $args['show_available_translations'] );
printf( '<select name="%s" id="%s">', esc_attr( $args['name'] ), esc_attr( $args['id'] ) );
$output = sprintf( '<select name="%s" id="%s">', esc_attr( $args['name'] ), esc_attr( $args['id'] ) );
// Holds the HTML markup.
$structure = array();
@ -950,7 +955,13 @@ function wp_dropdown_languages( $args = array() ) {
$structure[] = '</optgroup>';
}
echo join( "\n", $structure );
$output .= join( "\n", $structure );
echo '</select>';
$output .= '</select>';
if ( $args['echo'] ) {
echo $output;
}
return $output;
}

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.3-alpha-32509';
$wp_version = '4.3-alpha-32510';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.