[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

title

Body

[close]

/wp-admin/includes/ -> class-walker-category-checklist.php (source)

   1  <?php
   2  /**
   3   * Taxonomy API: Walker_Category_Checklist class
   4   *
   5   * @package WordPress
   6   * @subpackage Administration
   7   * @since 4.4.0
   8   */
   9  
  10  /**
  11   * Core walker class to output an unordered list of category checkbox input elements.
  12   *
  13   * @since 2.5.1
  14   *
  15   * @see Walker
  16   * @see wp_category_checklist()
  17   * @see wp_terms_checklist()
  18   */
  19  class Walker_Category_Checklist extends Walker {
  20      public $tree_type = 'category';
  21      public $db_fields = array(
  22          'parent' => 'parent',
  23          'id'     => 'term_id',
  24      ); //TODO: decouple this
  25  
  26      /**
  27       * Starts the list before the elements are added.
  28       *
  29       * @see Walker:start_lvl()
  30       *
  31       * @since 2.5.1
  32       *
  33       * @param string $output Used to append additional content (passed by reference).
  34       * @param int    $depth  Depth of category. Used for tab indentation.
  35       * @param array  $args   An array of arguments. @see wp_terms_checklist()
  36       */
  37  	public function start_lvl( &$output, $depth = 0, $args = array() ) {
  38          $indent  = str_repeat( "\t", $depth );
  39          $output .= "$indent<ul class='children'>\n";
  40      }
  41  
  42      /**
  43       * Ends the list of after the elements are added.
  44       *
  45       * @see Walker::end_lvl()
  46       *
  47       * @since 2.5.1
  48       *
  49       * @param string $output Used to append additional content (passed by reference).
  50       * @param int    $depth  Depth of category. Used for tab indentation.
  51       * @param array  $args   An array of arguments. @see wp_terms_checklist()
  52       */
  53  	public function end_lvl( &$output, $depth = 0, $args = array() ) {
  54          $indent  = str_repeat( "\t", $depth );
  55          $output .= "$indent</ul>\n";
  56      }
  57  
  58      /**
  59       * Start the element output.
  60       *
  61       * @see Walker::start_el()
  62       *
  63       * @since 2.5.1
  64       *
  65       * @param string $output   Used to append additional content (passed by reference).
  66       * @param object $category The current term object.
  67       * @param int    $depth    Depth of the term in reference to parents. Default 0.
  68       * @param array  $args     An array of arguments. @see wp_terms_checklist()
  69       * @param int    $id       ID of the current term.
  70       */
  71  	public function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) {
  72          if ( empty( $args['taxonomy'] ) ) {
  73              $taxonomy = 'category';
  74          } else {
  75              $taxonomy = $args['taxonomy'];
  76          }
  77  
  78          if ( $taxonomy == 'category' ) {
  79              $name = 'post_category';
  80          } else {
  81              $name = 'tax_input[' . $taxonomy . ']';
  82          }
  83  
  84          $args['popular_cats'] = empty( $args['popular_cats'] ) ? array() : $args['popular_cats'];
  85          $class                = in_array( $category->term_id, $args['popular_cats'] ) ? ' class="popular-category"' : '';
  86  
  87          $args['selected_cats'] = empty( $args['selected_cats'] ) ? array() : $args['selected_cats'];
  88  
  89          if ( ! empty( $args['list_only'] ) ) {
  90              $aria_checked = 'false';
  91              $inner_class  = 'category';
  92  
  93              if ( in_array( $category->term_id, $args['selected_cats'] ) ) {
  94                  $inner_class .= ' selected';
  95                  $aria_checked = 'true';
  96              }
  97  
  98              $output .= "\n" . '<li' . $class . '>' .
  99                  '<div class="' . $inner_class . '" data-term-id=' . $category->term_id .
 100                  ' tabindex="0" role="checkbox" aria-checked="' . $aria_checked . '">' .
 101                  /** This filter is documented in wp-includes/category-template.php */
 102                  esc_html( apply_filters( 'the_category', $category->name, '', '' ) ) . '</div>';
 103          } else {
 104              $output .= "\n<li id='{$taxonomy}-{$category->term_id}'$class>" .
 105                  '<label class="selectit"><input value="' . $category->term_id . '" type="checkbox" name="' . $name . '[]" id="in-' . $taxonomy . '-' . $category->term_id . '"' .
 106                  checked( in_array( $category->term_id, $args['selected_cats'] ), true, false ) .
 107                  disabled( empty( $args['disabled'] ), false, false ) . ' /> ' .
 108                  /** This filter is documented in wp-includes/category-template.php */
 109                  esc_html( apply_filters( 'the_category', $category->name, '', '' ) ) . '</label>';
 110          }
 111      }
 112  
 113      /**
 114       * Ends the element output, if needed.
 115       *
 116       * @see Walker::end_el()
 117       *
 118       * @since 2.5.1
 119       *
 120       * @param string $output   Used to append additional content (passed by reference).
 121       * @param object $category The current term object.
 122       * @param int    $depth    Depth of the term in reference to parents. Default 0.
 123       * @param array  $args     An array of arguments. @see wp_terms_checklist()
 124       */
 125  	public function end_el( &$output, $category, $depth = 0, $args = array() ) {
 126          $output .= "</li>\n";
 127      }
 128  }


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