| @@ -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 | * |
| @@ -21,15 +18,15 @@ | ||
| 21 | 18 | * @param int $depth Depth of the item. |
| 22 | 19 | * @param array $args An array of additional arguments. |
| 23 | 20 | * @param int $current_object_id ID of the current item. |
| 24 | 21 | */ |
| 25 | - public function start_el( &$output, $element, $depth = 0, $args = array(), $current_object_id = 0 ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable | |
| 22 | + public function start_el( &$output, $element, $depth = 0, $args = array(), $current_object_id = 0 ) { | |
| 26 | 23 | $value = $args['value']; |
| 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 | |
| @@ -44,9 +41,9 @@ | ||
| 44 | 41 | * @param int $depth Depth of current element. |
| 45 | 42 | * @param array $args An array of arguments. |
| 46 | 43 | * @param string $output Passed by reference. Used to append additional content. |
| 47 | 44 | */ |
| 48 | - public function display_element( $element, &$children_elements, $max_depth, $depth, $args, &$output ) { | |
| 45 | + public function display_element( $element, &$children_elements, $max_depth, $depth = 0, $args, &$output ) { | |
| 49 | 46 | $element = (object) $element; // Make sure we have an object |
| 50 | 47 | $element->parent = $element->id = 0; // Don't care about this |
| 51 | 48 | parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output ); |
| 52 | 49 | } |
| @@ -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 | } |