PluginProbe
Polylang / 3.4
Polylang v3.4
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.php

walker.php in Polylang 3.4, at include/walker.php

74 lines 2.3 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 * A class for displaying various tree-like language structures.
8 *
9 * Extend the `PLL_Walker` class to use it, and implement some of the methods from `Walker`.
10 * See: {https://developer.wordpress.org/reference/classes/walker/#methods}.
11 *
12 * @since 3.4
13 */
14 class PLL_Walker extends Walker {
15 /**
16 * Database fields to use.
17 *
18 * @see https://developer.wordpress.org/reference/classes/walker/#properties Walker::$db_fields.
19 *
20 * @var string[]
21 */
22 public $db_fields = array( 'parent' => 'parent', 'id' => 'id' );
23
24 /**
25 * Overrides Walker::display_element as it expects an object with a parent property.
26 *
27 * @since 1.2
28 * @since 3.4 Refactored and moved in `PLL_Walker`.
29 *
30 * @param PLL_Language|stdClass $element Data object. `PLL_language` in our case.
31 * @param array $children_elements List of elements to continue traversing.
32 * @param int $max_depth Max depth to traverse.
33 * @param int $depth Depth of current element.
34 * @param array $args An array of arguments.
35 * @param string $output Passed by reference. Used to append additional content.
36 * @return void
37 */
38 public function display_element( $element, &$children_elements, $max_depth, $depth, $args, &$output ) {
39 if ( $element instanceof PLL_Language ) {
40 $element = $element->to_std_class();
41 }
42
43 $element->parent = $element->id = 0; // Don't care about this.
44
45 parent::display_element( $element, $children_elements, $max_depth, $depth, $args, $output );
46 }
47
48 /**
49 * Sets `PLL_Walker::walk()` arguments as it should
50 * and triggers an error in case of misuse of them.
51 *
52 * @since 3.4
53 *
54 * @param array|int $max_depth The maximum hierarchical depth. Passed by reference.
55 * @param array $args Additional arguments. Passed by reference.
56 * @return void
57 */
58 protected function maybe_fix_walk_args( &$max_depth, &$args ) {
59 if ( ! is_array( $max_depth ) ) {
60 $args = isset( $args[0] ) ? $args[0] : array();
61 return;
62 }
63
64 // Backward compatibility with Polylang < 2.6.7
65 _doing_it_wrong(
66 __CLASS__ . '::walk()',
67 'The method expects an integer as second parameter.',
68 '2.6.7'
69 );
70 $args = $max_depth;
71 $max_depth = -1;
72 }
73 }
74