/wp-admin/includes/class-walker-category-checklist.php

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