PluginProbe
Polylang / 2.1
Polylang v2.1
3.8.9 3.8.8 3.8.7 3.8.6 3.8.5 3.8.4 3.8.3 2.7 2.7.0.1 2.7.1 2.7.2 2.7.3 2.7.4 2.8 2.8.1 2.8.2 2.8.3 2.8.4 2.9 2.9.1 2.9.2 3.0 3.0.1 3.0.2 3.0.3 All 233 releases
← All changes | include/walker-dropdown.php +25 -56 2.8.22.1 View file →
@@ -1,64 +1,51 @@
1 1 <?php
2 -/**
3 - * @package Polylang
4 - */
5 2
6 3 /**
7 - * Displays languages in a dropdown list
4 + * displays languages in a dropdown list
8 5 *
9 6 * @since 1.2
10 7 */
11 8 class PLL_Walker_Dropdown extends Walker {
12 - public $db_fields = array( 'parent' => 'parent', 'id' => 'id' );
9 + var $db_fields = array( 'parent' => 'parent', 'id' => 'id' );
13 10
14 11 /**
15 - * Outputs one element
12 + * outputs one element
16 13 *
17 14 * @since 1.2
18 15 *
19 - * @param string $output Passed by reference. Used to append additional content.
20 - * @param object $element The data object.
21 - * @param int $depth Depth of the item.
22 - * @param array $args An array of additional arguments.
23 - * @param int $current_object_id ID of the current item.
16 + * @see Walker::start_el
24 17 */
25 - public function start_el( &$output, $element, $depth = 0, $args = array(), $current_object_id = 0 ) {
18 + function start_el( &$output, $element, $depth = 0, $args = array(), $current_object_id = 0 ) {
26 19 $value = $args['value'];
27 20 $output .= sprintf(
28 - "\t" . '<option value="%1$s"%2$s%3$s>%4$s</option>' . "\n",
21 + "\t".'<option value="%1$s"%2$s%3$s>%4$s</option>'."\n",
29 22 esc_attr( $element->$value ),
30 - method_exists( $element, 'get_locale' ) ? sprintf( ' lang="%s"', esc_attr( $element->get_locale( 'display' ) ) ) : '',
31 - selected( isset( $args['selected'] ) && $args['selected'] === $element->$value, true, false ),
23 + empty( $element->locale ) ? '' : sprintf( ' lang="%s"', esc_attr( $element->locale ) ),
24 + isset( $args['selected'] ) && $args['selected'] === $element->$value ? ' selected="selected"' : '',
32 25 esc_html( $element->name )
33 26 );
34 27 }
35 28
36 29 /**
37 - * Overrides Walker::display_element as expects an object with a parent property
30 + * overrides Walker::display_element as expects an object with a parent property
38 31 *
39 32 * @since 1.2
40 33 *
41 - * @param object $element Data object.
42 - * @param array $children_elements List of elements to continue traversing.
43 - * @param int $max_depth Max depth to traverse.
44 - * @param int $depth Depth of current element.
45 - * @param array $args An array of arguments.
46 - * @param string $output Passed by reference. Used to append additional content.
34 + * @see Walker::display_element
47 35 */
48 - public function display_element( $element, &$children_elements, $max_depth, $depth = 0, $args, &$output ) {
49 - $element = (object) $element; // Make sure we have an object
50 - $element->parent = $element->id = 0; // Don't care about this
36 + function display_element( $element, &$children_elements, $max_depth, $depth = 0, $args, &$output ) {
37 + $element = (object) $element; // make sure we have an object
38 + $element->parent = $element->id = 0; // don't care about this
51 39 parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output );
52 40 }
53 41
54 42 /**
55 - * Starts the output of the dropdown list
43 + * starts the output of the dropdown list
56 44 *
57 45 * @since 1.2
58 - * @since 2.6.7 Use $max_depth and ...$args parameters to follow the move of WP 5.3
59 46 *
60 - * List of parameters accepted in $args:
47 + * list of parameters accepted in $args:
61 48 *
62 49 * flag => display the selected language flag in front of the dropdown if set to 1, defaults to 0
63 50 * value => the language field to use as value attribute, defaults to 'slug'
64 51 * selected => the selected value, mandatory
@@ -66,34 +53,16 @@
66 53 * id => the select id attribute, defaults to $args['name']
67 54 * class => the class attribute
68 55 * disabled => disables the dropdown if set to 1
69 56 *
70 - * @param array $elements An array of elements.
71 - * @param int $max_depth The maximum hierarchical depth.
72 - * @param mixed ...$args Additional arguments.
73 - * @return string The hierarchical item output.
57 + * @param array $elements elements to display
58 + * @param array $args
59 + * @return string
74 60 */
75 - public function walk( $elements, $max_depth, ...$args ) { // // phpcs:ignore WordPressVIPMinimum.Classes.DeclarationCompatibility.DeclarationCompatibility
61 + function walk( $elements, $args = array() ) {
76 62 $output = '';
63 + $args = wp_parse_args( $args, array( 'value' => 'slug', 'name' => 'lang_choice' ) );
77 64
78 - if ( is_array( $max_depth ) ) {
79 - // Backward compatibility with Polylang < 2.6.7
80 - if ( WP_DEBUG ) {
81 - trigger_error( // phpcs:ignore WordPress.PHP.DevelopmentFunctions
82 - sprintf(
83 - '%s was called incorrectly. The method expects an integer as second parameter since Polylang 2.6.7',
84 - __METHOD__
85 - )
86 - );
87 - }
88 - $args = $max_depth;
89 - $max_depth = -1;
90 - } else {
91 - $args = isset( $args[0] ) ? $args[0] : array();
92 - }
93 -
94 - $args = wp_parse_args( $args, array( 'value' => 'slug', 'name' => 'lang_choice' ) );
95 -
96 65 if ( ! empty( $args['flag'] ) ) {
97 66 $current = wp_list_filter( $elements, array( $args['value'] => $args['selected'] ) );
98 67 $lang = reset( $current );
99 68 $output = sprintf(
@@ -102,14 +71,14 @@
102 71 );
103 72 }
104 73
105 74 $output .= sprintf(
106 - '<select name="%1$s"%2$s%3$s%4$s>' . "\n" . '%5$s' . "\n" . '</select>' . "\n",
107 - esc_attr( $args['name'] ),
108 - isset( $args['id'] ) && ! $args['id'] ? '' : ' id="' . ( empty( $args['id'] ) ? esc_attr( $args['name'] ) : esc_attr( $args['id'] ) ) . '"',
75 + '<select name="%1$s"%2$s%3$s%4$s>' . "\n" . '%5$s' . "\n" . '</select>'."\n",
76 + $name = esc_attr( $args['name'] ),
77 + isset( $args['id'] ) && ! $args['id'] ? '' : ' id="' . ( empty( $args['id'] ) ? $name : esc_attr( $args['id'] ) ) . '"',
109 78 empty( $args['class'] ) ? '' : ' class="' . esc_attr( $args['class'] ) . '"',
110 - disabled( empty( $args['disabled'] ), false, false ),
111 - parent::walk( $elements, $max_depth, $args )
79 + empty( $args['disabled'] ) ? '' : ' disabled="disabled"',
80 + parent::walk( $elements, -1, $args )
112 81 );
113 82
114 83 return $output;
115 84 }