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