|
1 <?php |
|
2 /** |
|
3 * Post API: Walker_PageDropdown class |
|
4 * |
|
5 * @package WordPress |
|
6 * @subpackage Post |
|
7 * @since 4.4.0 |
|
8 */ |
|
9 |
|
10 /** |
|
11 * Core class used to create an HTML drop-down list of pages. |
|
12 * |
|
13 * @since 2.1.0 |
|
14 * |
|
15 * @see Walker |
|
16 */ |
|
17 class Walker_PageDropdown extends Walker { |
|
18 |
|
19 /** |
|
20 * What the class handles. |
|
21 * |
|
22 * @since 2.1.0 |
|
23 * @var string |
|
24 * |
|
25 * @see Walker::$tree_type |
|
26 */ |
|
27 public $tree_type = 'page'; |
|
28 |
|
29 /** |
|
30 * Database fields to use. |
|
31 * |
|
32 * @since 2.1.0 |
|
33 * @var array |
|
34 * |
|
35 * @see Walker::$db_fields |
|
36 * @todo Decouple this |
|
37 */ |
|
38 public $db_fields = array( 'parent' => 'post_parent', 'id' => 'ID' ); |
|
39 |
|
40 /** |
|
41 * Starts the element output. |
|
42 * |
|
43 * @since 2.1.0 |
|
44 * |
|
45 * @see Walker::start_el() |
|
46 * |
|
47 * @param string $output Used to append additional content. Passed by reference. |
|
48 * @param WP_Post $page Page data object. |
|
49 * @param int $depth Optional. Depth of page in reference to parent pages. Used for padding. |
|
50 * Default 0. |
|
51 * @param array $args Optional. Uses 'selected' argument for selected page to set selected HTML |
|
52 * attribute for option element. Uses 'value_field' argument to fill "value" |
|
53 * attribute. See wp_dropdown_pages(). Default empty array. |
|
54 * @param int $id Optional. ID of the current page. Default 0 (unused). |
|
55 */ |
|
56 public function start_el( &$output, $page, $depth = 0, $args = array(), $id = 0 ) { |
|
57 $pad = str_repeat(' ', $depth * 3); |
|
58 |
|
59 if ( ! isset( $args['value_field'] ) || ! isset( $page->{$args['value_field']} ) ) { |
|
60 $args['value_field'] = 'ID'; |
|
61 } |
|
62 |
|
63 $output .= "\t<option class=\"level-$depth\" value=\"" . esc_attr( $page->{$args['value_field']} ) . "\""; |
|
64 if ( $page->ID == $args['selected'] ) |
|
65 $output .= ' selected="selected"'; |
|
66 $output .= '>'; |
|
67 |
|
68 $title = $page->post_title; |
|
69 if ( '' === $title ) { |
|
70 /* translators: %d: ID of a post */ |
|
71 $title = sprintf( __( '#%d (no title)' ), $page->ID ); |
|
72 } |
|
73 |
|
74 /** |
|
75 * Filters the page title when creating an HTML drop-down list of pages. |
|
76 * |
|
77 * @since 3.1.0 |
|
78 * |
|
79 * @param string $title Page title. |
|
80 * @param object $page Page data object. |
|
81 */ |
|
82 $title = apply_filters( 'list_pages', $title, $page ); |
|
83 |
|
84 $output .= $pad . esc_html( $title ); |
|
85 $output .= "</option>\n"; |
|
86 } |
|
87 } |