| 1 |
<?php |
| 2 |
|
| 3 |
/* |
| 4 |
* displays languages in a dropdown list |
| 5 |
* |
| 6 |
* @since 1.2 |
| 7 |
*/ |
| 8 |
class PLL_Walker_Dropdown extends Walker { |
| 9 |
var $db_fields = array ('parent' => 'parent', 'id' => 'id'); |
| 10 |
|
| 11 |
/* |
| 12 |
* outputs one element |
| 13 |
* |
| 14 |
* @since 1.2 |
| 15 |
* |
| 16 |
* @see Walker::start_el |
| 17 |
*/ |
| 18 |
function start_el( &$output, $element, $depth = 0, $args = array(), $current_object_id = 0 ) { |
| 19 |
$value = isset($args['value']) && $args['value'] ? $args['value'] : 'slug'; |
| 20 |
$output .= sprintf( |
| 21 |
"\t".'<option value="%s"%s>%s</option>'."\n", |
| 22 |
esc_attr($element->$value), |
| 23 |
isset($args['selected']) && $args['selected'] == $element->$value ? ' selected="selected"' : '', |
| 24 |
esc_html($element->name) |
| 25 |
); |
| 26 |
} |
| 27 |
|
| 28 |
/* |
| 29 |
* overrides Walker::display_element as expects an object with a parent property |
| 30 |
* |
| 31 |
* @since 1.2 |
| 32 |
* |
| 33 |
* @see Walker::display_element |
| 34 |
*/ |
| 35 |
function display_element( $element, &$children_elements, $max_depth, $depth = 0, $args, &$output ) { |
| 36 |
$element = (object) $element; // make sure we have an object |
| 37 |
$element->parent = $element->id = 0; // don't care about this |
| 38 |
parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output ); |
| 39 |
} |
| 40 |
|
| 41 |
/* |
| 42 |
* starts teh output of the dropdown list |
| 43 |
* |
| 44 |
* @since 1.2 |
| 45 |
* |
| 46 |
* @param array $elements elements to display |
| 47 |
* @param array $args |
| 48 |
* @return string |
| 49 |
*/ |
| 50 |
function walk($elements, $args = array()) { |
| 51 |
return sprintf( |
| 52 |
'<select name="%1$s" id="%1$s"%2$s>' . "\n" . '%3$s' . "\n" . '</select>'."\n", |
| 53 |
empty($args['name']) ? 'lang_choice' : esc_attr($args['name']), |
| 54 |
empty($args['class']) ? '' : ' class="' . esc_attr($args['class']) . '"', |
| 55 |
parent::walk($elements, -1, $args) |
| 56 |
); |
| 57 |
} |
| 58 |
} |
| 59 |
|