PluginProbe
Polylang / 3.2.2
Polylang v3.2.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.2.2, at include/walker-list.php

97 lines 3.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 */
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 */
19 public $db_fields = array( 'parent' => 'parent', 'id' => 'id' );
20
21 /**
22 * Outputs one element
23 *
24 * @since 1.2
25 *
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
32 */
33 public function start_el( &$output, $element, $depth = 0, $args = array(), $current_object_id = 0 ) { // phpcs:ignore VariableAnalysis.CodeAnalysis.VariableAnalysis.UnusedVariable
34 $output .= sprintf(
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',
36 esc_attr( implode( ' ', $element->classes ) ),
37 esc_attr( $element->locale ),
38 esc_url( $element->url ),
39 $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",
43 empty( $element->link_classes ) ? '' : 'class="' . esc_attr( implode( ' ', $element->link_classes ) ) . '"'
44 );
45 }
46
47 /**
48 * Overrides Walker::display_element as it expects an object with a parent property
49 *
50 * @since 1.2
51 *
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
59 */
60 public function display_element( $element, &$children_elements, $max_depth, $depth, $args, &$output ) {
61 $element = (object) $element; // Make sure we have an object
62 $element->parent = $element->id = 0; // Don't care about this
63 parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output );
64 }
65
66 /**
67 * Overrides Walker:walk to set depth argument
68 *
69 * @since 1.2
70 * @since 2.6.7 Use $max_depth and ...$args parameters to follow the move of WP 5.3
71 *
72 * @param array $elements An array of elements.
73 * @param int $max_depth The maximum hierarchical depth.
74 * @param mixed ...$args Additional arguments.
75 * @return string The hierarchical item output.
76 */
77 public function walk( $elements, $max_depth, ...$args ) { // phpcs:ignore WordPressVIPMinimum.Classes.DeclarationCompatibility.DeclarationCompatibility
78 if ( is_array( $max_depth ) ) { // @phpstan-ignore-line
79 // Backward compatibility with Polylang < 2.6.7
80 if ( WP_DEBUG ) {
81 trigger_error( // phpcs:ignore WordPress.PHP.DevelopmentFunctions
82 sprintf(
83 '%s was called incorrectly. The method expects an integer as second parameter since Polylang 2.6.7',
84 __METHOD__
85 )
86 );
87 }
88 $args = $max_depth;
89 $max_depth = -1;
90 } else {
91 $args = isset( $args[0] ) ? $args[0] : array();
92 }
93
94 return parent::walk( $elements, $max_depth, $args );
95 }
96 }
97