[ Index ]

PHP Cross Reference of WordPress

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 string[]
  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       * @since 5.9.0 Renamed `$page` to `$data_object` and `$id` to `$current_object_id`
  48       *              to match parent class for PHP 8 named parameter support.
  49       *
  50       * @see Walker::start_el()
  51       *
  52       * @param string  $output            Used to append additional content. Passed by reference.
  53       * @param WP_Post $data_object       Page data object.
  54       * @param int     $depth             Optional. Depth of page in reference to parent pages.
  55       *                                   Used for padding. Default 0.
  56       * @param array   $args              Optional. Uses 'selected' argument for selected page to
  57       *                                   set selected HTML attribute for option element. Uses
  58       *                                   'value_field' argument to fill "value" attribute.
  59       *                                   See wp_dropdown_pages(). Default empty array.
  60       * @param int     $current_object_id Optional. ID of the current page. Default 0.
  61       */
  62  	public function start_el( &$output, $data_object, $depth = 0, $args = array(), $current_object_id = 0 ) {
  63          // Restores the more descriptive, specific name for use within this method.
  64          $page = $data_object;
  65          $pad  = str_repeat( '&nbsp;', $depth * 3 );
  66  
  67          if ( ! isset( $args['value_field'] ) || ! isset( $page->{$args['value_field']} ) ) {
  68              $args['value_field'] = 'ID';
  69          }
  70  
  71          $output .= "\t<option class=\"level-$depth\" value=\"" . esc_attr( $page->{$args['value_field']} ) . '"';
  72          if ( $page->ID == $args['selected'] ) {
  73              $output .= ' selected="selected"';
  74          }
  75          $output .= '>';
  76  
  77          $title = $page->post_title;
  78          if ( '' === $title ) {
  79              /* translators: %d: ID of a post. */
  80              $title = sprintf( __( '#%d (no title)' ), $page->ID );
  81          }
  82  
  83          /**
  84           * Filters the page title when creating an HTML drop-down list of pages.
  85           *
  86           * @since 3.1.0
  87           *
  88           * @param string  $title Page title.
  89           * @param WP_Post $page  Page data object.
  90           */
  91          $title = apply_filters( 'list_pages', $title, $page );
  92  
  93          $output .= $pad . esc_html( $title );
  94          $output .= "</option>\n";
  95      }
  96  }


Generated: Wed Jul 24 01:00:02 2024 Cross-referenced by PHPXref 0.7.1