| @@ 92-137 (lines=46) @@ | ||
| 89 | // foreach choices |
|
| 90 | if( !empty($field['choices']) ) { |
|
| 91 | ||
| 92 | foreach( $field['choices'] as $value => $label ) { |
|
| 93 | ||
| 94 | // increase counter |
|
| 95 | $i++; |
|
| 96 | ||
| 97 | ||
| 98 | // vars |
|
| 99 | $atts = array( |
|
| 100 | 'type' => 'checkbox', |
|
| 101 | 'id' => $field['id'], |
|
| 102 | 'name' => $field['name'], |
|
| 103 | 'value' => $value, |
|
| 104 | ); |
|
| 105 | ||
| 106 | ||
| 107 | // is choice selected? |
|
| 108 | if( in_array($value, $field['value']) ) { |
|
| 109 | ||
| 110 | $atts['checked'] = 'checked'; |
|
| 111 | ||
| 112 | } else { |
|
| 113 | ||
| 114 | $all_checked = false; |
|
| 115 | ||
| 116 | } |
|
| 117 | ||
| 118 | ||
| 119 | if( isset($field['disabled']) && acf_in_array($value, $field['disabled']) ) { |
|
| 120 | ||
| 121 | $atts['disabled'] = 'disabled'; |
|
| 122 | ||
| 123 | } |
|
| 124 | ||
| 125 | ||
| 126 | // each input ID is generated with the $key, however, the first input must not use $key so that it matches the field's label for attribute |
|
| 127 | if( $i > 1 ) { |
|
| 128 | ||
| 129 | $atts['id'] .= '-' . $value; |
|
| 130 | ||
| 131 | } |
|
| 132 | ||
| 133 | ||
| 134 | // append HTML |
|
| 135 | $li .= '<li><label><input ' . acf_esc_attr( $atts ) . '/>' . $label . '</label></li>'; |
|
| 136 | ||
| 137 | } |
|
| 138 | ||
| 139 | ||
| 140 | // toggle all |
|
| @@ 123-160 (lines=38) @@ | ||
| 120 | ||
| 121 | ||
| 122 | // foreach choices |
|
| 123 | foreach( $field['choices'] as $value => $label ) { |
|
| 124 | ||
| 125 | // increase counter |
|
| 126 | $i++; |
|
| 127 | ||
| 128 | ||
| 129 | // vars |
|
| 130 | $atts = array( |
|
| 131 | 'type' => 'radio', |
|
| 132 | 'id' => $field['id'], |
|
| 133 | 'name' => $field['name'], |
|
| 134 | 'value' => $value, |
|
| 135 | ); |
|
| 136 | ||
| 137 | ||
| 138 | if( strval($value) === strval($field['value']) ) { |
|
| 139 | ||
| 140 | $atts['checked'] = 'checked'; |
|
| 141 | $checked = true; |
|
| 142 | ||
| 143 | } |
|
| 144 | ||
| 145 | if( isset($field['disabled']) && acf_in_array($value, $field['disabled']) ) { |
|
| 146 | ||
| 147 | $atts['disabled'] = 'disabled'; |
|
| 148 | ||
| 149 | } |
|
| 150 | ||
| 151 | ||
| 152 | // each input ID is generated with the $key, however, the first input must not use $key so that it matches the field's label for attribute |
|
| 153 | if( $i > 1 ) { |
|
| 154 | ||
| 155 | $atts['id'] .= '-' . $value; |
|
| 156 | ||
| 157 | } |
|
| 158 | ||
| 159 | $e .= '<li><label><input ' . acf_esc_attr( $atts ) . '/>' . $label . '</label></li>'; |
|
| 160 | } |
|
| 161 | ||
| 162 | } |
|
| 163 | ||