| 1185 | * Print out the default text field for add_settings_field() |
| 1186 | * |
| 1187 | * This outputs the default text field for callback "text". |
| 1188 | * |
| 1189 | * @since 3.5.0 |
| 1190 | * |
| 1191 | * @param array $field Field arguments |
| 1192 | */ |
| 1193 | function do_settings_text( $field ) { |
| 1194 | |
| 1195 | $value = get_option( $field['id'] ); |
| 1196 | if( ! empty( $field['args']['default'] ) ) |
| 1197 | $value = $value !== false ? $value : $field['args']['default']; |
| 1198 | |
| 1199 | echo '<input type="text" class="regular-text" id="' . $field['id'] . '" name="' . $field['id'] . '" value="' . esc_attr( $value ) . '"/>'; |
| 1200 | |
| 1201 | if( !empty( $field['args']['description'] ) ) |
| 1202 | echo '<div class="description">' . $field['args']['description'] . '</div>'; |
| 1203 | |
| 1204 | } |
| 1205 | |
| 1206 | |
| 1207 | /** |
| 1208 | * Print out the default textarea field for add_settings_field() |
| 1209 | * |
| 1210 | * This outputs the default text field for callback "texarea". |
| 1211 | * |
| 1212 | * @since 3.5.0 |
| 1213 | * |
| 1214 | * @param array $field Field arguments |
| 1215 | */ |
| 1216 | function do_settings_textarea( $field ) { |
| 1217 | |
| 1218 | $value = get_option( $field['id'] ); |
| 1219 | if( ! empty( $field['args']['default'] ) ) |
| 1220 | $value = $value !== false ? $value : $field['args']['default']; |
| 1221 | |
| 1222 | echo '<textarea id="' . $field['id'] . '" name="' . $field['id'] . '" rows="10" cols="50" class="large-text">' . esc_attr( $value ) . '</textarea>'; |
| 1223 | |
| 1224 | if( !empty( $field['args']['description'] ) ) |
| 1225 | echo '<div class="description">' . $field['args']['description'] . '</div>'; |
| 1226 | |
| 1227 | } |
| 1228 | |
| 1229 | |
| 1230 | /** |
| 1231 | * Print out the default select field for add_settings_field() |
| 1232 | * |
| 1233 | * This outputs the default text field for callback "select". |
| 1234 | * |
| 1235 | * @since 3.5.0 |
| 1236 | * |
| 1237 | * @param array $field Field arguments |
| 1238 | */ |
| 1239 | function do_settings_select( $field ) { |
| 1240 | |
| 1241 | if( empty( $field['args']['choices'] ) ) |
| 1242 | return; |
| 1243 | |
| 1244 | $option = get_option( $field['id'] ); |
| 1245 | if( ! $option ) |
| 1246 | $option = ! empty( $field['args']['default'] ) ? $option : $field['args']['default']; |
| 1247 | |
| 1248 | echo '<select id="' . $field['id'] . '" name="' . $field['id'] . '">'; |
| 1249 | foreach( $field['args']['choices'] as $key => $choice ) { |
| 1250 | echo '<option value="' . $key . '" ' . selected( $key, $option, false ) . '>' . $choice . '</option>'; |
| 1251 | } |
| 1252 | echo '</select>'; |
| 1253 | |
| 1254 | if( !empty( $field['args']['description'] ) ) |
| 1255 | echo '<div class="description">' . $field['args']['description'] . '</div>'; |
| 1256 | |
| 1257 | } |
| 1258 | |
| 1259 | |
| 1260 | /** |
| 1261 | * Print out the default radio field for add_settings_field() |
| 1262 | * |
| 1263 | * This outputs the default text field for callback "radio". |
| 1264 | * |
| 1265 | * @since 3.5.0 |
| 1266 | * |
| 1267 | * @param array $field Field arguments |
| 1268 | */ |
| 1269 | function do_settings_radio( $field ) { |
| 1270 | |
| 1271 | if( empty( $field['args']['choices'] ) ) |
| 1272 | return; |
| 1273 | |
| 1274 | $option = get_option( $field['id'] ); |
| 1275 | if( ! empty( $field['args']['default'] ) ) |
| 1276 | $option = $option !== false ? $option : $field['args']['default']; |
| 1277 | |
| 1278 | |
| 1279 | foreach( $field['args']['choices'] as $key => $choice ) { |
| 1280 | echo '<label><input type="radio" name="' . $field['id'] . '" value="' . $key . '" ' . checked( $key, $option, false ) . '/> ' . $choice . '</label><br/>'; |
| 1281 | } |
| 1282 | |
| 1283 | if( !empty( $field['args']['description'] ) ) |
| 1284 | echo '<div class="description">' . $field['args']['description'] . '</div>'; |
| 1285 | |
| 1286 | } |
| 1287 | |
| 1288 | |
| 1289 | /** |
| 1290 | * Print out the default checkbox field for add_settings_field() |
| 1291 | * |
| 1292 | * This outputs the default text field for callback "checkbox". |
| 1293 | * |
| 1294 | * @since 3.5.0 |
| 1295 | * |
| 1296 | * @param array $field Field arguments |
| 1297 | */ |
| 1298 | function do_settings_checkbox( $field ) { |
| 1299 | |
| 1300 | $description = !empty( $field['args']['description'] ) ? $field['args']['description'] : ''; |
| 1301 | |
| 1302 | echo '<label><input type="checkbox" name="' . $field['id'] . '" value="1" ' . checked( 1, get_option( $field['id'] ), false ) . '/> ' . $description . '</label>'; |
| 1303 | |
| 1304 | } |
| 1305 | |
| 1306 | |
| 1307 | /** |
| 1308 | * Print out the default radio field for add_settings_field() |
| 1309 | * |
| 1310 | * This outputs the default text field for callback "radio". |
| 1311 | * |
| 1312 | * @since 3.5.0 |
| 1313 | * |
| 1314 | * @param array $field Field arguments |
| 1315 | */ |
| 1316 | function do_settings_checkbox_group( $field ) { |
| 1317 | |
| 1318 | if( empty( $field['args']['choices'] ) ) |
| 1319 | return; |
| 1320 | |
| 1321 | $options = get_option( $field['id'] ); |
| 1322 | $options = is_array( $options ) ? $options : array(); |
| 1323 | |
| 1324 | foreach( $field['args']['choices'] as $key => $choice ) { |
| 1325 | echo '<label><input type="checkbox" name="' . $field['id'] . '[' . $key . ']" value="' . $key . '" ' . checked( true, in_array( $key, $options ), false ) . '/> ' . $choice . '</label><br/>'; |
| 1326 | } |
| 1327 | |
| 1328 | if( !empty( $field['args']['description'] ) ) |
| 1329 | echo '<div class="description">' . $field['args']['description'] . '</div>'; |
| 1330 | |
| 1331 | } |
| 1332 | |
| 1333 | |
| 1334 | /** |