4.98KiB; PHP | 2020-03-23 19:12:58+01 | SLOC 107
1
<?php
2
/**
3
 * Navigation Menu API: Walker_Nav_Menu_Checklist class
4
 *
5
 * @package WordPress
6
 * @subpackage Administration
7
 * @since 4.4.0
8
 */
9
10
/**
11
 * Create HTML list of nav menu input items.
12
 *
13
 * @since 3.0.0
14
 * @uses Walker_Nav_Menu
15
 */
16 1
class Walker_Nav_Menu_Checklist extends Walker_Nav_Menu {
17
	/**
18
	 * @param array $fields
19
	 */
20 1
	public function __construct( $fields = false ) {
21
		if ( $fields ) {
22
			$this->db_fields = $fields;
23
		}
24
	}
25
26
	/**
27
	 * Starts the list before the elements are added.
28
	 *
29
	 * @see Walker_Nav_Menu::start_lvl()
30
	 *
31
	 * @since 3.0.0
32
	 *
33
	 * @param string $output Used to append additional content (passed by reference).
34
	 * @param int    $depth  Depth of page. Used for padding.
35
	 * @param array  $args   Not used.
36
	 */
37 2
	public function start_lvl( &$output, $depth = 0, $args = array() ) {
CamelCaseMethodName The method start_lvl is not named in camelCase. (kritika/PHPMD) Filter like this
UnusedFormalParameter Avoid unused parameters such as '$args'. (kritika/PHPMD) Filter like this
38
		$indent  = str_repeat( "\t", $depth );
39
		$output .= "\n$indent<ul class='children'>\n";
40
	}
41
42
	/**
43
	 * Ends the list of after the elements are added.
44
	 *
45
	 * @see Walker_Nav_Menu::end_lvl()
46
	 *
47
	 * @since 3.0.0
48
	 *
49
	 * @param string $output Used to append additional content (passed by reference).
50
	 * @param int    $depth  Depth of page. Used for padding.
51
	 * @param array  $args   Not used.
52
	 */
53 2
	public function end_lvl( &$output, $depth = 0, $args = array() ) {
54
		$indent  = str_repeat( "\t", $depth );
55
		$output .= "\n$indent</ul>";
56
	}
57
58
	/**
59
	 * Start the element output.
60
	 *
61
	 * @see Walker_Nav_Menu::start_el()
62
	 *
63
	 * @since 3.0.0
64
	 *
65
	 * @global int        $_nav_menu_placeholder
66
	 * @global int|string $nav_menu_selected_id
67
	 *
68
	 * @param string $output Used to append additional content (passed by reference).
69
	 * @param object $item   Menu item data object.
70
	 * @param int    $depth  Depth of menu item. Used for padding.
71
	 * @param array  $args   Not used.
72
	 * @param int    $id     Not used.
73
	 */
74 16
	public function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
75 1
		global $_nav_menu_placeholder, $nav_menu_selected_id;
76
77
		$_nav_menu_placeholder = ( 0 > $_nav_menu_placeholder ) ? intval( $_nav_menu_placeholder ) - 1 : -1;
78
		$possible_object_id    = isset( $item->post_type ) && 'nav_menu_item' == $item->post_type ? $item->object_id : $_nav_menu_placeholder;
79
		$possible_db_id        = ( ! empty( $item->ID ) ) && ( 0 < $possible_object_id ) ? (int) $item->ID : 0;
80
81
		$indent = ( $depth ) ? str_repeat( "\t", $depth ) : '';
82
83
		$output .= $indent . '<li>';
84
		$output .= '<label class="menu-item-title">';
85
		$output .= '<input type="checkbox"' . wp_nav_menu_disabled_check( $nav_menu_selected_id, false ) . ' class="menu-item-checkbox';
86
87
		if ( ! empty( $item->front_or_home ) ) {
88
			$output .= ' add-to-top';
89
		}
90
91
		$output .= '" name="menu-item[' . $possible_object_id . '][menu-item-object-id]" value="' . esc_attr( $item->object_id ) . '" /> ';
92
93
		if ( ! empty( $item->label ) ) {
94
			$title = $item->label;
95
		} elseif ( isset( $item->post_type ) ) {
96
			/** This filter is documented in wp-includes/post-template.php */
97
			$title = apply_filters( 'the_title', $item->post_title, $item->ID );
98
		}
99
100
		$output .= isset( $title ) ? esc_html( $title ) : esc_html( $item->title );
101
102
		if ( empty( $item->label ) && isset( $item->post_type ) && 'page' === $item->post_type ) {
103
			// Append post states.
104
			$output .= _post_states( $item, false );
105
		}
106
107
		$output .= '</label>';
108
109
		// Menu item hidden fields
110
		$output .= '<input type="hidden" class="menu-item-db-id" name="menu-item[' . $possible_object_id . '][menu-item-db-id]" value="' . $possible_db_id . '" />';
111
		$output .= '<input type="hidden" class="menu-item-object" name="menu-item[' . $possible_object_id . '][menu-item-object]" value="' . esc_attr( $item->object ) . '" />';
112
		$output .= '<input type="hidden" class="menu-item-parent-id" name="menu-item[' . $possible_object_id . '][menu-item-parent-id]" value="' . esc_attr( $item->menu_item_parent ) . '" />';
113
		$output .= '<input type="hidden" class="menu-item-type" name="menu-item[' . $possible_object_id . '][menu-item-type]" value="' . esc_attr( $item->type ) . '" />';
114
		$output .= '<input type="hidden" class="menu-item-title" name="menu-item[' . $possible_object_id . '][menu-item-title]" value="' . esc_attr( $item->title ) . '" />';
115
		$output .= '<input type="hidden" class="menu-item-url" name="menu-item[' . $possible_object_id . '][menu-item-url]" value="' . esc_attr( $item->url ) . '" />';
116
		$output .= '<input type="hidden" class="menu-item-target" name="menu-item[' . $possible_object_id . '][menu-item-target]" value="' . esc_attr( $item->target ) . '" />';
117
		$output .= '<input type="hidden" class="menu-item-attr-title" name="menu-item[' . $possible_object_id . '][menu-item-attr-title]" value="' . esc_attr( $item->attr_title ) . '" />';
118
		$output .= '<input type="hidden" class="menu-item-classes" name="menu-item[' . $possible_object_id . '][menu-item-classes]" value="' . esc_attr( implode( ' ', $item->classes ) ) . '" />';
119
		$output .= '<input type="hidden" class="menu-item-xfn" name="menu-item[' . $possible_object_id . '][menu-item-xfn]" value="' . esc_attr( $item->xfn ) . '" />';
120
	}
121
122
} // Walker_Nav_Menu_Checklist