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