[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

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 {@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 {@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       * @since 5.9.0 Renamed `$category` to `$data_object` and `$id` to `$current_object_id`
  65       *              to match parent class for PHP 8 named parameter support.
  66       *
  67       * @param string  $output            Used to append additional content (passed by reference).
  68       * @param WP_Term $data_object       The current term object.
  69       * @param int     $depth             Depth of the term in reference to parents. Default 0.
  70       * @param array   $args              An array of arguments. See {@see wp_terms_checklist()}.
  71       * @param int     $current_object_id Optional. ID of the current term. Default 0.
  72       */
  73  	public function start_el( &$output, $data_object, $depth = 0, $args = array(), $current_object_id = 0 ) {
  74          // Restores the more descriptive, specific name for use within this method.
  75          $category = $data_object;
  76  
  77          if ( empty( $args['taxonomy'] ) ) {
  78              $taxonomy = 'category';
  79          } else {
  80              $taxonomy = $args['taxonomy'];
  81          }
  82  
  83          if ( 'category' === $taxonomy ) {
  84              $name = 'post_category';
  85          } else {
  86              $name = 'tax_input[' . $taxonomy . ']';
  87          }
  88  
  89          $args['popular_cats'] = ! empty( $args['popular_cats'] ) ? array_map( 'intval', $args['popular_cats'] ) : array();
  90  
  91          $class = in_array( $category->term_id, $args['popular_cats'], true ) ? ' class="popular-category"' : '';
  92  
  93          $args['selected_cats'] = ! empty( $args['selected_cats'] ) ? array_map( 'intval', $args['selected_cats'] ) : array();
  94  
  95          if ( ! empty( $args['list_only'] ) ) {
  96              $aria_checked = 'false';
  97              $inner_class  = 'category';
  98  
  99              if ( in_array( $category->term_id, $args['selected_cats'], true ) ) {
 100                  $inner_class .= ' selected';
 101                  $aria_checked = 'true';
 102              }
 103  
 104              $output .= "\n" . '<li' . $class . '>' .
 105                  '<div class="' . $inner_class . '" data-term-id=' . $category->term_id .
 106                  ' tabindex="0" role="checkbox" aria-checked="' . $aria_checked . '">' .
 107                  /** This filter is documented in wp-includes/category-template.php */
 108                  esc_html( apply_filters( 'the_category', $category->name, '', '' ) ) . '</div>';
 109          } else {
 110              $is_selected = in_array( $category->term_id, $args['selected_cats'], true );
 111              $is_disabled = ! empty( $args['disabled'] );
 112  
 113              $output .= "\n<li id='{$taxonomy}-{$category->term_id}'$class>" .
 114                  '<label class="selectit"><input value="' . $category->term_id . '" type="checkbox" name="' . $name . '[]" id="in-' . $taxonomy . '-' . $category->term_id . '"' .
 115                  checked( $is_selected, true, false ) .
 116                  disabled( $is_disabled, true, false ) . ' /> ' .
 117                  /** This filter is documented in wp-includes/category-template.php */
 118                  esc_html( apply_filters( 'the_category', $category->name, '', '' ) ) . '</label>';
 119          }
 120      }
 121  
 122      /**
 123       * Ends the element output, if needed.
 124       *
 125       * @see Walker::end_el()
 126       *
 127       * @since 2.5.1
 128       * @since 5.9.0 Renamed `$category` to `$data_object` to match parent class for PHP 8 named parameter support.
 129       *
 130       * @param string  $output      Used to append additional content (passed by reference).
 131       * @param WP_Term $data_object The current term object.
 132       * @param int     $depth       Depth of the term in reference to parents. Default 0.
 133       * @param array   $args        An array of arguments. See {@see wp_terms_checklist()}.
 134       */
 135  	public function end_el( &$output, $data_object, $depth = 0, $args = array() ) {
 136          $output .= "</li>\n";
 137      }
 138  }


Generated : Tue Apr 23 08:20:01 2024 Cross-referenced by PHPXref