PluginProbe
Polylang / 3.7.2
Polylang v3.7.2
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
polylang / include / walker-list.php

walker-list.php in Polylang 3.7.2, at include/walker-list.php

91 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package Polylang
4 */
5
6 /**
7 * Displays a language list
8 *
9 * @since 1.2
10 * @since 3.4 Extends `PLL_Walker` now.
11 */
12 class PLL_Walker_List extends PLL_Walker {
13 /**
14 * Database fields to use.
15 *
16 * @see https://developer.wordpress.org/reference/classes/walker/#properties Walker::$db_fields.
17 *
18 * @var string[]
19 */
20 public $db_fields = array( 'parent' => 'parent', 'id' => 'id' );
21
22 /**
23 * Outputs one element
24 *
25 * @since 1.2
26 *
27 * @param string $output Passed by reference. Used to append additional content.
28 * @param stdClass $element The data object.
29 * @param int $depth Depth of the item.
30 * @param array $args An array of additional arguments.
31 * @param int $current_object_id ID of the current item.
32 * @return void
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
63 $output .= sprintf(
64 '%5$s<li class="%1$s"><a %2$s>%3$s%4$s</a></li>%6$s',
65 esc_attr( implode( ' ', $element->classes ) ),
66 $link_atts,
67 $element->flag,
68 $label,
69 'discard' === $args['item_spacing'] ? '' : "\t",
70 'discard' === $args['item_spacing'] ? '' : "\n"
71 );
72 }
73
74 /**
75 * Overrides Walker:walk to set depth argument
76 *
77 * @since 1.2
78 * @since 2.6.7 Use $max_depth and ...$args parameters to follow the move of WP 5.3
79 *
80 * @param array $elements An array of elements.
81 * @param int $max_depth The maximum hierarchical depth.
82 * @param mixed ...$args Additional arguments.
83 * @return string The hierarchical item output.
84 */
85 public function walk( $elements, $max_depth, ...$args ) { // phpcs:ignore WordPressVIPMinimum.Classes.DeclarationCompatibility.DeclarationCompatibility
86 $this->maybe_fix_walk_args( $max_depth, $args );
87
88 return parent::walk( $elements, $max_depth, $args );
89 }
90 }
91