[ Index ]

PHP Cross Reference of BuddyPress

title

Body

[close]

/src/bp-core/classes/ -> class-bp-walker-category-checklist.php (source)

   1  <?php
   2  /**
   3   * Walker class to output an unordered list of category checkbox input elements.
   4   *
   5   * A modification of WordPress 4.4.1's Walker_Category_Checklist class which prints term description
   6   * instead of term name, and makes it work for non-hierarchical taxonomys. Some lines have undergone
   7   * slight adjustment to meet modern coding standards, but any improvements should be contributed upstream.
   8   *
   9   * @since 2.5.0
  10   */
  11  class BP_Walker_Category_Checklist extends Walker {
  12      public $tree_type = 'category';
  13      public $db_fields = array( 'parent' => 'parent', 'id' => 'term_id' );
  14  
  15      /**
  16       * Starts the list before the elements are added.
  17       *
  18       * @since 2.5.0
  19       *
  20       * @param string $output Passed by reference. Used to append additional content.
  21       * @param int    $depth  Depth of category. Used for tab indentation.
  22       * @param array  $args   An array of arguments.
  23       */
  24  	public function start_lvl( &$output, $depth = 0, $args = array() ) {
  25          $indent  = str_repeat( "\t", $depth );
  26          $output .= "$indent<ul class='children'>\n";
  27      }
  28  
  29      /**
  30       * Ends the list of after the elements are added.
  31       *
  32       * @since 2.5.0
  33       *
  34       * @param string $output Passed by reference. Used to append additional content.
  35       * @param int    $depth  Depth of category. Used for tab indentation.
  36       * @param array  $args   An array of arguments.
  37       */
  38  	public function end_lvl( &$output, $depth = 0, $args = array() ) {
  39          $indent = str_repeat( "\t", $depth );
  40          $output .= "$indent</ul>\n";
  41      }
  42  
  43      /**
  44       * Start the element output.
  45       *
  46       * @param string $output   Passed by reference. Used to append additional content.
  47       * @param object $category The current term object.
  48       * @param int    $depth    Depth of the term in reference to parents. Default 0.
  49       * @param array  $args     An array of arguments.
  50       * @param int    $id       ID of the current term.
  51       */
  52  	public function start_el( &$output, $category, $depth = 0, $args = array(), $id = 0 ) {
  53          if ( empty( $args['taxonomy'] ) ) {
  54              $taxonomy = 'category';
  55          } else {
  56              $taxonomy = $args['taxonomy'];
  57          }
  58  
  59          if ( $taxonomy == 'category' ) {
  60              $name = 'post_category';
  61          } else {
  62              $name = 'tax_input[' . $taxonomy . ']';
  63          }
  64  
  65          $args['popular_cats'] = empty( $args['popular_cats'] ) ? array() : $args['popular_cats'];
  66          $class = in_array( $category->term_id, $args['popular_cats'] ) ? ' class="popular-category"' : '';
  67  
  68          $args['selected_cats'] = empty( $args['selected_cats'] ) ? array() : $args['selected_cats'];
  69  
  70          if ( ! empty( $args['list_only'] ) ) {
  71              $aria_cheched = 'false';
  72              $inner_class = 'category';
  73  
  74              if ( in_array( $category->term_id, $args['selected_cats'] ) ) {
  75                  $inner_class .= ' selected';
  76                  $aria_cheched = 'true';
  77              }
  78  
  79              /** This filter is documented in wp-includes/category-template.php */
  80              $output .= "\n" . '<li' . $class . '>' .
  81                  '<div class="' . $inner_class . '" data-term-id=' . $category->term_id .
  82                  ' tabindex="0" role="checkbox" aria-checked="' . $aria_cheched . '">' .
  83                  esc_html( apply_filters( 'the_category', $category->description ) ) . '</div>';
  84          } else {
  85              /** This filter is documented in wp-includes/category-template.php */
  86              $output .= "\n<li id='{$taxonomy}-{$category->term_id}'$class>" .
  87                  '<label for="in-'.$taxonomy.'-' . $category->term_id . '" class="selectit"><input value="' . $category->slug . '" type="checkbox" name="'.$name.'[]" id="in-'.$taxonomy.'-' . $category->term_id . '"' .
  88                  checked( in_array( $category->term_id, $args['selected_cats'] ), true, false ) .
  89                  disabled( empty( $args['disabled'] ), false, false ) . ' /> ' .
  90                  esc_html( apply_filters( 'the_category', $category->description ) ) . '</label>';
  91          }
  92      }
  93  
  94      /**
  95       * Ends the element output, if needed.
  96       *
  97       * @see Walker::end_el()
  98       *
  99       * @since 2.5.0
 100       *
 101       * @param string $output   Passed by reference. Used to append additional content.
 102       * @param object $category The current term object.
 103       * @param int    $depth    Depth of the term in reference to parents. Default 0.
 104       * @param array  $args     An array of arguments. @see wp_terms_checklist()
 105       */
 106  	public function end_el( &$output, $category, $depth = 0, $args = array() ) {
 107          $output .= "</li>\n";
 108      }
 109  }


Generated: Thu Nov 21 01:00:57 2024 Cross-referenced by PHPXref 0.7.1