PluginProbe
Polylang / 3.7.1
Polylang v3.7.1
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-list.php +35 -40 3.0.33.7.1 View file →
@@ -6,16 +6,17 @@
6 6 /**
7 7 * Displays a language list
8 8 *
9 9 * @since 1.2
10 + * @since 3.4 Extends `PLL_Walker` now.
10 11 */
11 -class PLL_Walker_List extends Walker {
12 +class PLL_Walker_List extends PLL_Walker {
12 13 /**
13 14 * Database fields to use.
14 15 *
15 16 * @see https://developer.wordpress.org/reference/classes/walker/#properties Walker::$db_fields.
16 17 *
17 - * @var array
18 + * @var string[]
18 19 */
19 20 public $db_fields = array( 'parent' => 'parent', 'id' => 'id' );
20 21
21 22 /**
@@ -30,15 +31,42 @@
30 31 * @param int $current_object_id ID of the current item.
31 32 * @return void
32 33 */
33 34 public function start_el( &$output, $element, $depth = 0, $args = array(), $current_object_id = 0 ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
35 + // Link attributes.
36 + $link_atts = sprintf(
37 + 'lang="%1$s" hreflang="%1$s" href="%2$s"',
38 + esc_attr( $element->locale ),
39 + esc_url( $element->url )
40 + );
41 +
42 + if ( ! empty( $element->link_classes ) ) {
43 + $link_atts .= sprintf(
44 + ' class="%s"',
45 + esc_attr( implode( ' ', $element->link_classes ) )
46 + );
47 + }
48 + if ( ! empty( $element->current_lang ) ) {
49 + $link_atts .= ' aria-current="true"';
50 + }
51 +
52 + // Text label.
53 + if ( $args['show_flags'] && $args['show_names'] ) {
54 + $label = sprintf(
55 + '<span style="margin-%1$s:0.3em;">%2$s</span>',
56 + is_rtl() ? 'right' : 'left',
57 + esc_html( $element->name )
58 + );
59 + } else {
60 + $label = esc_html( $element->name );
61 + }
62 +
34 63 $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',
64 + '%5$s<li class="%1$s"><a %2$s>%3$s%4$s</a></li>%6$s',
36 65 esc_attr( implode( ' ', $element->classes ) ),
37 - esc_attr( $element->locale ),
38 - esc_url( $element->url ),
66 + $link_atts,
39 67 $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 ),
68 + $label,
41 69 'discard' === $args['item_spacing'] ? '' : "\t",
42 70 'discard' === $args['item_spacing'] ? '' : "\n"
43 71 );
44 72 }
@@ -43,27 +71,8 @@
43 71 );
44 72 }
45 73
46 74 /**
47 - * Overrides Walker::display_element as it expects an object with a parent property
48 - *
49 - * @since 1.2
50 - *
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
58 - */
59 - public function display_element( $element, &$children_elements, $max_depth, $depth, $args, &$output ) {
60 - $element = (object) $element; // Make sure we have an object
61 - $element->parent = $element->id = 0; // Don't care about this
62 - parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output );
63 - }
64 -
65 - /**
66 75 * Overrides Walker:walk to set depth argument
67 76 *
68 77 * @since 1.2
69 78 * @since 2.6.7 Use $max_depth and ...$args parameters to follow the move of WP 5.3
@@ -73,23 +82,9 @@
73 82 * @param mixed ...$args Additional arguments.
74 83 * @return string The hierarchical item output.
75 84 */
76 85 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 - }
86 + $this->maybe_fix_walk_args( $max_depth, $args );
92 87
93 88 return parent::walk( $elements, $max_depth, $args );
94 89 }
95 90 }