[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

title

Body

[close]

/wp-includes/ -> class-walker-page-dropdown.php (source)

   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(
  39          'parent' => 'post_parent',
  40          'id'     => 'ID',
  41      );
  42  
  43      /**
  44       * Starts the element output.
  45       *
  46       * @since 2.1.0
  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          }
  70          $output .= '>';
  71  
  72          $title = $page->post_title;
  73          if ( '' === $title ) {
  74              /* translators: %d: ID of a post. */
  75              $title = sprintf( __( '#%d (no title)' ), $page->ID );
  76          }
  77  
  78          /**
  79           * Filters the page title when creating an HTML drop-down list of pages.
  80           *
  81           * @since 3.1.0
  82           *
  83           * @param string  $title Page title.
  84           * @param WP_Post $page  Page data object.
  85           */
  86          $title = apply_filters( 'list_pages', $title, $page );
  87  
  88          $output .= $pad . esc_html( $title );
  89          $output .= "</option>\n";
  90      }
  91  }


Generated: Tue Oct 22 08:20:01 2019 Cross-referenced by PHPXref 0.7