| @@ -1,8 +1,5 @@ | ||
| 1 | 1 | <?php |
| 2 | -/** | |
| 3 | - * @package Polylang | |
| 4 | - */ | |
| 5 | 2 | |
| 6 | 3 | /** |
| 7 | 4 | * Displays a language list |
| 8 | 5 | * |
| @@ -8,16 +5,9 @@ | ||
| 8 | 5 | * |
| 9 | 6 | * @since 1.2 |
| 10 | 7 | */ |
| 11 | 8 | class PLL_Walker_List extends Walker { |
| 12 | - /** | |
| 13 | - * Database fields to use. | |
| 14 | - * | |
| 15 | - * @see https://developer.wordpress.org/reference/classes/walker/#properties Walker::$db_fields. | |
| 16 | - * | |
| 17 | - * @var array | |
| 18 | - */ | |
| 19 | - public $db_fields = array( 'parent' => 'parent', 'id' => 'id' ); | |
| 9 | + var $db_fields = array( 'parent' => 'parent', 'id' => 'id' ); | |
| 20 | 10 | |
| 21 | 11 | /** |
| 22 | 12 | * Outputs one element |
| 23 | 13 | * |
| @@ -22,25 +12,18 @@ | ||
| 22 | 12 | * Outputs one element |
| 23 | 13 | * |
| 24 | 14 | * @since 1.2 |
| 25 | 15 | * |
| 26 | - * @param string $output Passed by reference. Used to append additional content. | |
| 27 | - * @param stdClass $element The data object. | |
| 28 | - * @param int $depth Depth of the item. | |
| 29 | - * @param array $args An array of additional arguments. | |
| 30 | - * @param int $current_object_id ID of the current item. | |
| 31 | - * @return void | |
| 16 | + * @see Walker::start_el | |
| 32 | 17 | */ |
| 33 | - public function start_el( &$output, $element, $depth = 0, $args = array(), $current_object_id = 0 ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable | |
| 18 | + function start_el( &$output, $element, $depth = 0, $args = array(), $current_object_id = 0 ) { | |
| 34 | 19 | $output .= sprintf( |
| 35 | - '%6$s<li class="%1$s"><a lang="%2$s" hreflang="%2$s" href="%3$s">%4$s%5$s</a></li>%7$s', | |
| 20 | + "\t".'<li class="%1$s"><a lang="%2$s" hreflang="%2$s" href="%3$s">%4$s%5$s</a></li>'."\n", | |
| 36 | 21 | esc_attr( implode( ' ', $element->classes ) ), |
| 37 | 22 | esc_attr( $element->locale ), |
| 38 | 23 | esc_url( $element->url ), |
| 39 | 24 | $element->flag, |
| 40 | - $args['show_flags'] && $args['show_names'] ? sprintf( '<span style="margin-%1$s:0.3em;">%2$s</span>', is_rtl() ? 'right' : 'left', esc_html( $element->name ) ) : esc_html( $element->name ), | |
| 41 | - 'discard' === $args['item_spacing'] ? '' : "\t", | |
| 42 | - 'discard' === $args['item_spacing'] ? '' : "\n" | |
| 25 | + $args['show_flags'] && $args['show_names'] ? '<span style="margin-left:0.3em;">' . esc_html( $element->name ) . '</span>' : esc_html( $element->name ) | |
| 43 | 26 | ); |
| 44 | 27 | } |
| 45 | 28 | |
| 46 | 29 | /** |
| @@ -47,17 +30,11 @@ | ||
| 47 | 30 | * Overrides Walker::display_element as it expects an object with a parent property |
| 48 | 31 | * |
| 49 | 32 | * @since 1.2 |
| 50 | 33 | * |
| 51 | - * @param stdClass $element Data object. | |
| 52 | - * @param array $children_elements List of elements to continue traversing. | |
| 53 | - * @param int $max_depth Max depth to traverse. | |
| 54 | - * @param int $depth Depth of current element. | |
| 55 | - * @param array $args An array of arguments. | |
| 56 | - * @param string $output Passed by reference. Used to append additional content. | |
| 57 | - * @return void | |
| 34 | + * @see Walker::display_element | |
| 58 | 35 | */ |
| 59 | - public function display_element( $element, &$children_elements, $max_depth, $depth, $args, &$output ) { | |
| 36 | + function display_element( $element, &$children_elements, $max_depth, $depth = 0, $args, &$output ) { | |
| 60 | 37 | $element = (object) $element; // Make sure we have an object |
| 61 | 38 | $element->parent = $element->id = 0; // Don't care about this |
| 62 | 39 | parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output ); |
| 63 | 40 | } |
| @@ -65,31 +42,13 @@ | ||
| 65 | 42 | /** |
| 66 | 43 | * Overrides Walker:walk to set depth argument |
| 67 | 44 | * |
| 68 | 45 | * @since 1.2 |
| 69 | - * @since 2.6.7 Use $max_depth and ...$args parameters to follow the move of WP 5.3 | |
| 70 | 46 | * |
| 71 | - * @param array $elements An array of elements. | |
| 72 | - * @param int $max_depth The maximum hierarchical depth. | |
| 73 | - * @param mixed ...$args Additional arguments. | |
| 74 | - * @return string The hierarchical item output. | |
| 47 | + * @param array $elements elements to display | |
| 48 | + * @param array $args | |
| 49 | + * @return string | |
| 75 | 50 | */ |
| 76 | - public function walk( $elements, $max_depth, ...$args ) { // phpcs:ignore WordPressVIPMinimum.Classes.DeclarationCompatibility.DeclarationCompatibility | |
| 77 | - if ( is_array( $max_depth ) ) { // @phpstan-ignore-line | |
| 78 | - // Backward compatibility with Polylang < 2.6.7 | |
| 79 | - if ( WP_DEBUG ) { | |
| 80 | - trigger_error( // phpcs:ignore WordPress.PHP.DevelopmentFunctions | |
| 81 | - sprintf( | |
| 82 | - '%s was called incorrectly. The method expects an integer as second parameter since Polylang 2.6.7', | |
| 83 | - __METHOD__ | |
| 84 | - ) | |
| 85 | - ); | |
| 86 | - } | |
| 87 | - $args = $max_depth; | |
| 88 | - $max_depth = -1; | |
| 89 | - } else { | |
| 90 | - $args = isset( $args[0] ) ? $args[0] : array(); | |
| 91 | - } | |
| 92 | - | |
| 93 | - return parent::walk( $elements, $max_depth, $args ); | |
| 51 | + function walk( $elements, $args = array() ) { | |
| 52 | + return parent::walk( $elements, -1, $args ); | |
| 94 | 53 | } |
| 95 | 54 | } |