Allow `wp_dropdown_languages()` to return the markup instead of displaying.
props leewillis77, juliobox. fixes #32432. git-svn-id: https://develop.svn.wordpress.org/trunk@32510 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
d800ebdf96
commit
03e04a0c1c
|
@ -851,6 +851,7 @@ function wp_get_pomo_file_data( $po_file ) {
|
||||||
* Language selector.
|
* Language selector.
|
||||||
*
|
*
|
||||||
* @since 4.0.0
|
* @since 4.0.0
|
||||||
|
* @since 4.3.0 Introduced the `echo` argument.
|
||||||
*
|
*
|
||||||
* @see get_available_languages()
|
* @see get_available_languages()
|
||||||
* @see wp_get_available_translations()
|
* @see wp_get_available_translations()
|
||||||
|
@ -865,8 +866,11 @@ function wp_get_pomo_file_data( $po_file ) {
|
||||||
* @type array $translations List of available translations. Default result of
|
* @type array $translations List of available translations. Default result of
|
||||||
* {@see wp_get_available_translations()}.
|
* {@see wp_get_available_translations()}.
|
||||||
* @type string $selected Language which should be selected. Default empty.
|
* @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.
|
* @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() ) {
|
function wp_dropdown_languages( $args = array() ) {
|
||||||
|
|
||||||
|
@ -876,6 +880,7 @@ function wp_dropdown_languages( $args = array() ) {
|
||||||
'languages' => array(),
|
'languages' => array(),
|
||||||
'translations' => array(),
|
'translations' => array(),
|
||||||
'selected' => '',
|
'selected' => '',
|
||||||
|
'echo' => 1,
|
||||||
'show_available_translations' => true,
|
'show_available_translations' => true,
|
||||||
) );
|
) );
|
||||||
|
|
||||||
|
@ -912,7 +917,7 @@ function wp_dropdown_languages( $args = array() ) {
|
||||||
|
|
||||||
$translations_available = ( ! empty( $translations ) && $args['show_available_translations'] );
|
$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.
|
// Holds the HTML markup.
|
||||||
$structure = array();
|
$structure = array();
|
||||||
|
@ -950,7 +955,13 @@ function wp_dropdown_languages( $args = array() ) {
|
||||||
$structure[] = '</optgroup>';
|
$structure[] = '</optgroup>';
|
||||||
}
|
}
|
||||||
|
|
||||||
echo join( "\n", $structure );
|
$output .= join( "\n", $structure );
|
||||||
|
|
||||||
echo '</select>';
|
$output .= '</select>';
|
||||||
|
|
||||||
|
if ( $args['echo'] ) {
|
||||||
|
echo $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $output;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue