123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- <?php
- if ( ! defined( 'ABSPATH' ) ) {
- exit;
- }
- if ( ! class_exists( 'ACF_Taxonomy_Field_Walker' ) ) :
- class ACF_Taxonomy_Field_Walker extends Walker {
-
- public $tree_type = 'category';
-
- public $db_fields = array(
- 'parent' => 'parent',
- 'id' => 'term_id',
- );
-
- public $field;
-
- function __construct( $field ) {
- $this->field = $field;
- }
-
- public function start_lvl( &$output, $depth = 0, $args = array() ) {
- $indent = str_repeat( "\t", $depth );
- $output .= "$indent<ul class='children acf-bl'>\n";
- }
-
- public function end_lvl( &$output, $depth = 0, $args = array() ) {
- $indent = str_repeat( "\t", $depth );
- $output .= "$indent</ul>\n";
- }
-
- public function start_el( &$output, $term, $depth = 0, $args = array(), $id = 0 ) {
- $is_selected = in_array( $term->term_id, $this->field['value'] );
-
- $input_attrs = array(
- 'type' => $this->field['field_type'],
- 'name' => $this->field['name'],
- 'value' => $term->term_id,
- );
- if ( $is_selected ) {
- $input_attrs['checked'] = true;
- }
- $output .= "\n" . '<li data-id="' . esc_attr( $term->term_id ) . '">' .
- '<label' . ( $is_selected ? ' class="selected"' : '' ) . '>' .
- '<input ' . acf_esc_attrs( $input_attrs ) . '/> ' .
- '<span>' . acf_esc_html( $term->name ) . '</span>' .
- '</label>';
- }
-
- public function end_el( &$output, $category, $depth = 0, $args = array() ) {
- $output .= "</li>\n";
- }
- }
- endif;
|