PluginProbe
Polylang / 2.5
Polylang v2.5
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 +9 -31 2.82.5 View file →
@@ -1,8 +1,5 @@
1 1 <?php
2 -/**
3 - * @package Polylang
4 - */
5 2
6 3 /**
7 4 * Displays languages in a dropdown list
8 5 *
@@ -27,9 +24,9 @@
27 24 $output .= sprintf(
28 25 "\t" . '<option value="%1$s"%2$s%3$s>%4$s</option>' . "\n",
29 26 esc_attr( $element->$value ),
30 27 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 ),
28 + isset( $args['selected'] ) && $args['selected'] === $element->$value ? ' selected="selected"' : '',
32 29 esc_html( $element->name )
33 30 );
34 31 }
35 32
@@ -54,9 +51,8 @@
54 51 /**
55 52 * Starts the output of the dropdown list
56 53 *
57 54 * @since 1.2
58 - * @since 2.6.7 Use $max_depth and ...$args parameters to follow the move of WP 5.3
59 55 *
60 56 * List of parameters accepted in $args:
61 57 *
62 58 * flag => display the selected language flag in front of the dropdown if set to 1, defaults to 0
@@ -66,32 +62,14 @@
66 62 * id => the select id attribute, defaults to $args['name']
67 63 * class => the class attribute
68 64 * disabled => disables the dropdown if set to 1
69 65 *
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.
66 + * @param array $elements elements to display
67 + * @param array $args
68 + * @return string
74 69 */
75 - public function walk( $elements, $max_depth, ...$args ) { // // phpcs:ignore WordPressVIPMinimum.Classes.DeclarationCompatibility.DeclarationCompatibility
70 + public function walk( $elements, $args = array() ) {
76 71 $output = '';
77 -
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 72 $args = wp_parse_args( $args, array( 'value' => 'slug', 'name' => 'lang_choice' ) );
95 73
96 74 if ( ! empty( $args['flag'] ) ) {
97 75 $current = wp_list_filter( $elements, array( $args['value'] => $args['selected'] ) );
@@ -103,13 +81,13 @@
103 81 }
104 82
105 83 $output .= sprintf(
106 84 '<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'] ) ) . '"',
85 + $name = esc_attr( $args['name'] ),
86 + isset( $args['id'] ) && ! $args['id'] ? '' : ' id="' . ( empty( $args['id'] ) ? $name : esc_attr( $args['id'] ) ) . '"',
109 87 empty( $args['class'] ) ? '' : ' class="' . esc_attr( $args['class'] ) . '"',
110 - disabled( empty( $args['disabled'] ), false, false ),
111 - parent::walk( $elements, $max_depth, $args )
88 + empty( $args['disabled'] ) ? '' : ' disabled="disabled"',
89 + parent::walk( $elements, -1, $args )
112 90 );
113 91
114 92 return $output;
115 93 }