]> scripts.mit.edu Git - autoinstalls/wordpress.git/blob - wp-includes/class-walker-page-dropdown.php
WordPress 4.4.1
[autoinstalls/wordpress.git] / wp-includes / class-walker-page-dropdown.php
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          * @see Walker::$tree_type
20          * @since 2.1.0
21          * @var string
22          */
23         public $tree_type = 'page';
24
25         /**
26          * @see Walker::$db_fields
27          * @since 2.1.0
28          * @todo Decouple this
29          * @var array
30          */
31         public $db_fields = array ('parent' => 'post_parent', 'id' => 'ID');
32
33         /**
34          * @see Walker::start_el()
35          * @since 2.1.0
36          *
37          * @param string $output Passed by reference. Used to append additional content.
38          * @param object $page   Page data object.
39          * @param int    $depth  Depth of page in reference to parent pages. Used for padding.
40          * @param array  $args   Uses 'selected' argument for selected page to set selected HTML attribute for option
41          *                       element. Uses 'value_field' argument to fill "value" attribute. See {@see wp_dropdown_pages()}.
42          * @param int    $id
43          */
44         public function start_el( &$output, $page, $depth = 0, $args = array(), $id = 0 ) {
45                 $pad = str_repeat('&nbsp;', $depth * 3);
46
47                 if ( ! isset( $args['value_field'] ) || ! isset( $page->{$args['value_field']} ) ) {
48                         $args['value_field'] = 'ID';
49                 }
50
51                 $output .= "\t<option class=\"level-$depth\" value=\"" . esc_attr( $page->{$args['value_field']} ) . "\"";
52                 if ( $page->ID == $args['selected'] )
53                         $output .= ' selected="selected"';
54                 $output .= '>';
55
56                 $title = $page->post_title;
57                 if ( '' === $title ) {
58                         /* translators: %d: ID of a post */
59                         $title = sprintf( __( '#%d (no title)' ), $page->ID );
60                 }
61
62                 /**
63                  * Filter the page title when creating an HTML drop-down list of pages.
64                  *
65                  * @since 3.1.0
66                  *
67                  * @param string $title Page title.
68                  * @param object $page  Page data object.
69                  */
70                 $title = apply_filters( 'list_pages', $title, $page );
71                 $output .= $pad . esc_html( $title );
72                 $output .= "</option>\n";
73         }
74 }