PluginProbe ʕ •ᴥ•ʔ
Secure Custom Fields / 6.9.5
Secure Custom Fields v6.9.5
6.9.5 6.9.4 6.9.3 6.9.2 6.9.1 6.9.0 6.8.9 6.8.7 6.8.8 6.8.6 6.8.4 6.8.5 trunk 6.4.0-beta1 6.4.0-beta2 6.4.1 6.4.1-beta3 6.4.1-beta4 6.4.1-beta5 6.4.1-beta6 6.4.1-beta7 6.4.2 6.5.0 6.5.1 6.5.2 6.5.3 6.5.4 6.5.5 6.5.6 6.5.7 6.6.0 6.7.0 6.7.1 6.8.0 6.8.1 6.8.2 6.8.3
secure-custom-fields / includes / walkers / class-acf-walker-taxonomy-field.php
secure-custom-fields / includes / walkers Last commit date
class-acf-walker-taxonomy-field.php 1 year ago index.php 1 year ago
class-acf-walker-taxonomy-field.php
134 lines
1 <?php
2
3 if ( ! defined( 'ABSPATH' ) ) {
4 exit; // Exit if accessed directly
5 }
6
7 if ( ! class_exists( 'ACF_Taxonomy_Field_Walker' ) ) :
8
9 class ACF_Taxonomy_Field_Walker extends Walker {
10
11 /**
12 * What the class handles.
13 *
14 * @since ACF 2.1.0
15 * @var string
16 */
17 public $tree_type = 'category';
18
19 /**
20 * DB fields to use.
21 *
22 * @since ACF 2.1.0
23 * @var array
24 */
25 public $db_fields = array(
26 'parent' => 'parent',
27 'id' => 'term_id',
28 );
29
30 /**
31 * The field being rendered.
32 *
33 * @since ACF 1.0.0
34 * @var array
35 */
36 public $field;
37
38 /**
39 * Constructor
40 *
41 * @date 20/4/21
42 * @since ACF 1.0.0
43 *
44 * @param array $field The field being rendered.
45 * @return void
46 */
47 function __construct( $field ) {
48 $this->field = $field;
49 }
50
51 /**
52 * Starts the list before the elements are added.
53 *
54 * @see Walker:start_lvl()
55 *
56 * @since ACF 1.0.0
57 *
58 * @param string $output Used to append additional content (passed by reference).
59 * @param integer $depth Depth of category. Used for tab indentation.
60 * @param array $args An array of arguments. @see wp_terms_checklist()
61 */
62 public function start_lvl( &$output, $depth = 0, $args = array() ) {
63 $indent = str_repeat( "\t", $depth );
64 $output .= "$indent<ul class='children acf-bl'>\n";
65 }
66
67 /**
68 * Ends the list of after the elements are added.
69 *
70 * @see Walker::end_lvl()
71 *
72 * @since ACF 1.0.0
73 *
74 * @param string $output Used to append additional content (passed by reference).
75 * @param integer $depth Depth of category. Used for tab indentation.
76 * @param array $args An array of arguments. @see wp_terms_checklist()
77 */
78 public function end_lvl( &$output, $depth = 0, $args = array() ) {
79 $indent = str_repeat( "\t", $depth );
80 $output .= "$indent</ul>\n";
81 }
82
83 /**
84 * Start the element output.
85 *
86 * @see Walker::start_el()
87 *
88 * @since ACF 1.0.0
89 *
90 * @param string $output Used to append additional content (passed by reference).
91 * @param WP_Term $term The current term object.
92 * @param integer $depth Depth of the term in reference to parents. Default 0.
93 * @param array $args An array of arguments. @see wp_terms_checklist()
94 * @param integer $id ID of the current term.
95 */
96 public function start_el( &$output, $term, $depth = 0, $args = array(), $id = 0 ) {
97 $is_selected = in_array( $term->term_id, $this->field['value'] );
98
99 // Generate array of checkbox input attributes.
100 $input_attrs = array(
101 'type' => $this->field['field_type'],
102 'name' => $this->field['name'],
103 'value' => $term->term_id,
104 );
105 if ( $is_selected ) {
106 $input_attrs['checked'] = true;
107 }
108
109 $output .= "\n" . '<li data-id="' . esc_attr( $term->term_id ) . '">' .
110 '<label' . ( $is_selected ? ' class="selected"' : '' ) . '>' .
111 '<input ' . acf_esc_attrs( $input_attrs ) . '/> ' .
112 '<span>' . acf_esc_html( $term->name ) . '</span>' .
113 '</label>';
114 }
115
116 /**
117 * Ends the element output, if needed.
118 *
119 * @see Walker::end_el()
120 *
121 * @since ACF 1.0.0
122 *
123 * @param string $output Used to append additional content (passed by reference).
124 * @param WP_Term $category The current term object.
125 * @param integer $depth Depth of the term in reference to parents. Default 0.
126 * @param array $args An array of arguments. @see wp_terms_checklist()
127 */
128 public function end_el( &$output, $category, $depth = 0, $args = array() ) {
129 $output .= "</li>\n";
130 }
131 }
132
133 endif;
134