| @@ -8,8 +8,15 @@ | ||
| 8 | 8 | * |
| 9 | 9 | * @since 1.2 |
| 10 | 10 | */ |
| 11 | 11 | 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 | + */ | |
| 12 | 19 | public $db_fields = array( 'parent' => 'parent', 'id' => 'id' ); |
| 13 | 20 | |
| 14 | 21 | /** |
| 15 | 22 | * Outputs one element |
| @@ -15,17 +22,18 @@ | ||
| 15 | 22 | * Outputs one element |
| 16 | 23 | * |
| 17 | 24 | * @since 1.2 |
| 18 | 25 | * |
| 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. | |
| 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 | |
| 24 | 32 | */ |
| 25 | 33 | public function start_el( &$output, $element, $depth = 0, $args = array(), $current_object_id = 0 ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable |
| 26 | 34 | $output .= sprintf( |
| 27 | - '%6$s<li class="%1$s"><a lang="%2$s" hreflang="%2$s" href="%3$s">%4$s%5$s</a></li>%7$s', | |
| 35 | + '%6$s<li class="%1$s"><a %8$s lang="%2$s" hreflang="%2$s" href="%3$s">%4$s%5$s</a></li>%7$s', | |
| 28 | 36 | esc_attr( implode( ' ', $element->classes ) ), |
| 29 | 37 | esc_attr( $element->locale ), |
| 30 | 38 | esc_url( $element->url ), |
| 31 | 39 | $element->flag, |
| @@ -30,9 +38,10 @@ | ||
| 30 | 38 | esc_url( $element->url ), |
| 31 | 39 | $element->flag, |
| 32 | 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 ), |
| 33 | 41 | 'discard' === $args['item_spacing'] ? '' : "\t", |
| 34 | - 'discard' === $args['item_spacing'] ? '' : "\n" | |
| 42 | + 'discard' === $args['item_spacing'] ? '' : "\n", | |
| 43 | + empty( $element->link_classes ) ? '' : 'class="' . esc_attr( implode( ' ', $element->link_classes ) ) . '"' | |
| 35 | 44 | ); |
| 36 | 45 | } |
| 37 | 46 | |
| 38 | 47 | /** |
| @@ -39,14 +48,15 @@ | ||
| 39 | 48 | * Overrides Walker::display_element as it expects an object with a parent property |
| 40 | 49 | * |
| 41 | 50 | * @since 1.2 |
| 42 | 51 | * |
| 43 | - * @param object $element Data object. | |
| 44 | - * @param array $children_elements List of elements to continue traversing. | |
| 45 | - * @param int $max_depth Max depth to traverse. | |
| 46 | - * @param int $depth Depth of current element. | |
| 47 | - * @param array $args An array of arguments. | |
| 48 | - * @param string $output Passed by reference. Used to append additional content. | |
| 52 | + * @param stdClass $element Data object. | |
| 53 | + * @param array $children_elements List of elements to continue traversing. | |
| 54 | + * @param int $max_depth Max depth to traverse. | |
| 55 | + * @param int $depth Depth of current element. | |
| 56 | + * @param array $args An array of arguments. | |
| 57 | + * @param string $output Passed by reference. Used to append additional content. | |
| 58 | + * @return void | |
| 49 | 59 | */ |
| 50 | 60 | public function display_element( $element, &$children_elements, $max_depth, $depth, $args, &$output ) { |
| 51 | 61 | $element = (object) $element; // Make sure we have an object |
| 52 | 62 | $element->parent = $element->id = 0; // Don't care about this |
| @@ -64,9 +74,9 @@ | ||
| 64 | 74 | * @param mixed ...$args Additional arguments. |
| 65 | 75 | * @return string The hierarchical item output. |
| 66 | 76 | */ |
| 67 | 77 | public function walk( $elements, $max_depth, ...$args ) { // phpcs:ignore WordPressVIPMinimum.Classes.DeclarationCompatibility.DeclarationCompatibility |
| 68 | - if ( is_array( $max_depth ) ) { | |
| 78 | + if ( is_array( $max_depth ) ) { // @phpstan-ignore-line | |
| 69 | 79 | // Backward compatibility with Polylang < 2.6.7 |
| 70 | 80 | if ( WP_DEBUG ) { |
| 71 | 81 | trigger_error( // phpcs:ignore WordPress.PHP.DevelopmentFunctions |
| 72 | 82 | sprintf( |