| | 1272 | function get_bastardized_media_item( $attachment_id, $args = null ) { |
| | 1273 | $post = get_post( $attachment_id ); |
| | 1274 | |
| | 1275 | $default_args = array( |
| | 1276 | 'errors' => null, |
| | 1277 | ); |
| | 1278 | |
| | 1279 | $args = wp_parse_args( $args, $default_args ); |
| | 1280 | $args = apply_filters( 'get_media_item_args', $args ); |
| | 1281 | |
| | 1282 | $errors = $args['errors']; |
| | 1283 | |
| | 1284 | $form_fields = get_attachment_fields_to_edit( $post, $errors ); |
| | 1285 | |
| | 1286 | $media_meta = apply_filters( 'media_meta', '', $post ); |
| | 1287 | |
| | 1288 | $defaults = array( |
| | 1289 | 'input' => 'text', |
| | 1290 | 'required' => false, |
| | 1291 | 'value' => '', |
| | 1292 | 'extra_rows' => array(), |
| | 1293 | ); |
| | 1294 | |
| | 1295 | $hidden_fields = array(); |
| | 1296 | |
| | 1297 | unset( $form_fields['image-size'], $form_fields['align'], $form_fields['image_alt'], |
| | 1298 | $form_fields['post_title'], $form_fields['post_excerpt'], $form_fields['post_content'], |
| | 1299 | $form_fields['url'], $form_fields['menu_order'], $form_fields['image_url'] ); |
| | 1300 | |
| | 1301 | $item = ''; |
| | 1302 | foreach ( $form_fields as $name => $field ) { |
| | 1303 | if ( $name[0] == '_' ) |
| | 1304 | continue; |
| | 1305 | |
| | 1306 | if ( !empty( $field['tr'] ) ) { |
| | 1307 | $item .= $field['tr']; |
| | 1308 | continue; |
| | 1309 | } |
| | 1310 | |
| | 1311 | $field = array_merge( $defaults, $field ); |
| | 1312 | |
| | 1313 | if ( $field['input'] == 'hidden' ) { |
| | 1314 | $hidden_fields[$name] = $field['value']; |
| | 1315 | continue; |
| | 1316 | } |
| | 1317 | |
| | 1318 | $required = $field['required'] ? '<span class="alignright"><abbr title="required" class="required">*</abbr></span>' : ''; |
| | 1319 | $aria_required = $field['required'] ? " aria-required='true' " : ''; |
| | 1320 | $class = $name; |
| | 1321 | $class .= $field['required'] ? ' form-required' : ''; |
| | 1322 | |
| | 1323 | $item .= "\t\t<tr class='$class'>"; |
| | 1324 | $item .= "\t\t\t<th valign='top' scope='row' class='label'><label for='$name'><span class='alignleft'>{$field['label']}</span>$required<br class='clear' /></label>"; |
| | 1325 | $item .= "</th>\n\t\t\t<td class='field'>"; |
| | 1326 | |
| | 1327 | if ( !empty( $field[ $field['input'] ] ) ) |
| | 1328 | $item .= $field[ $field['input'] ]; |
| | 1329 | elseif ( $field['input'] == 'textarea' ) { |
| | 1330 | if ( 'post_content' == $name && user_can_richedit() ) { |
| | 1331 | // sanitize_post() skips the post_content when user_can_richedit |
| | 1332 | $field['value'] = htmlspecialchars( $field['value'], ENT_QUOTES ); |
| | 1333 | } |
| | 1334 | $item .= "<textarea id='$name' name='$name' $aria_required>" . $field['value'] . '</textarea>'; |
| | 1335 | } else { |
| | 1336 | $item .= "<input type='text' class='text' id='$name' name='$name' value='" . esc_attr( $field['value'] ) . "' $aria_required />"; |
| | 1337 | } |
| | 1338 | if ( !empty( $field['helps'] ) ) |
| | 1339 | $item .= "<p class='help'>" . join( "</p>\n<p class='help'>", array_unique( (array) $field['helps'] ) ) . '</p>'; |
| | 1340 | $item .= "</td>\n\t\t</tr>\n"; |
| | 1341 | |
| | 1342 | $extra_rows = array(); |
| | 1343 | |
| | 1344 | if ( !empty( $field['errors'] ) ) |
| | 1345 | foreach ( array_unique( (array) $field['errors'] ) as $error ) |
| | 1346 | $extra_rows['error'][] = $error; |
| | 1347 | |
| | 1348 | if ( !empty( $field['extra_rows'] ) ) |
| | 1349 | foreach ( $field['extra_rows'] as $class => $rows ) |
| | 1350 | foreach ( (array) $rows as $html ) |
| | 1351 | $extra_rows[$class][] = $html; |
| | 1352 | |
| | 1353 | foreach ( $extra_rows as $class => $rows ) |
| | 1354 | foreach ( $rows as $html ) |
| | 1355 | $item .= "\t\t<tr><td></td><td class='$class'>$html</td></tr>\n"; |
| | 1356 | } |
| | 1357 | |
| | 1358 | if ( !empty( $form_fields['_final'] ) ) |
| | 1359 | $item .= "\t\t<tr class='final'><td colspan='2'>{$form_fields['_final']}</td></tr>\n"; |
| | 1360 | if ( $item ) |
| | 1361 | $item = '<table>' . $item . '</table>'; |
| | 1362 | |
| | 1363 | return compact( 'item', 'hidden_fields', 'media_meta' ); |
| | 1364 | } |
| | 1365 | |