Edit File by line
/home/barbar84/www/wp-admin/includes
File: media.php
* @param string $file The URL of the image to download.
[1000] Fix | Delete
*/
[1001] Fix | Delete
$allowed_extensions = apply_filters( 'image_sideload_extensions', $allowed_extensions, $file );
[1002] Fix | Delete
$allowed_extensions = array_map( 'preg_quote', $allowed_extensions );
[1003] Fix | Delete
[1004] Fix | Delete
// Set variables for storage, fix file filename for query strings.
[1005] Fix | Delete
preg_match( '/[^\?]+\.(' . implode( '|', $allowed_extensions ) . ')\b/i', $file, $matches );
[1006] Fix | Delete
[1007] Fix | Delete
if ( ! $matches ) {
[1008] Fix | Delete
return new WP_Error( 'image_sideload_failed', __( 'Invalid image URL.' ) );
[1009] Fix | Delete
}
[1010] Fix | Delete
[1011] Fix | Delete
$file_array = array();
[1012] Fix | Delete
$file_array['name'] = wp_basename( $matches[0] );
[1013] Fix | Delete
[1014] Fix | Delete
// Download file to temp location.
[1015] Fix | Delete
$file_array['tmp_name'] = download_url( $file );
[1016] Fix | Delete
[1017] Fix | Delete
// If error storing temporarily, return the error.
[1018] Fix | Delete
if ( is_wp_error( $file_array['tmp_name'] ) ) {
[1019] Fix | Delete
return $file_array['tmp_name'];
[1020] Fix | Delete
}
[1021] Fix | Delete
[1022] Fix | Delete
// Do the validation and storage stuff.
[1023] Fix | Delete
$id = media_handle_sideload( $file_array, $post_id, $desc );
[1024] Fix | Delete
[1025] Fix | Delete
// If error storing permanently, unlink.
[1026] Fix | Delete
if ( is_wp_error( $id ) ) {
[1027] Fix | Delete
@unlink( $file_array['tmp_name'] );
[1028] Fix | Delete
return $id;
[1029] Fix | Delete
}
[1030] Fix | Delete
[1031] Fix | Delete
// Store the original attachment source in meta.
[1032] Fix | Delete
add_post_meta( $id, '_source_url', $file );
[1033] Fix | Delete
[1034] Fix | Delete
// If attachment ID was requested, return it.
[1035] Fix | Delete
if ( 'id' === $return ) {
[1036] Fix | Delete
return $id;
[1037] Fix | Delete
}
[1038] Fix | Delete
[1039] Fix | Delete
$src = wp_get_attachment_url( $id );
[1040] Fix | Delete
}
[1041] Fix | Delete
[1042] Fix | Delete
// Finally, check to make sure the file has been saved, then return the HTML.
[1043] Fix | Delete
if ( ! empty( $src ) ) {
[1044] Fix | Delete
if ( 'src' === $return ) {
[1045] Fix | Delete
return $src;
[1046] Fix | Delete
}
[1047] Fix | Delete
[1048] Fix | Delete
$alt = isset( $desc ) ? esc_attr( $desc ) : '';
[1049] Fix | Delete
$html = "<img src='$src' alt='$alt' />";
[1050] Fix | Delete
[1051] Fix | Delete
return $html;
[1052] Fix | Delete
} else {
[1053] Fix | Delete
return new WP_Error( 'image_sideload_failed' );
[1054] Fix | Delete
}
[1055] Fix | Delete
}
[1056] Fix | Delete
[1057] Fix | Delete
/**
[1058] Fix | Delete
* Retrieves the legacy media uploader form in an iframe.
[1059] Fix | Delete
*
[1060] Fix | Delete
* @since 2.5.0
[1061] Fix | Delete
*
[1062] Fix | Delete
* @return string|null
[1063] Fix | Delete
*/
[1064] Fix | Delete
function media_upload_gallery() {
[1065] Fix | Delete
$errors = array();
[1066] Fix | Delete
[1067] Fix | Delete
if ( ! empty( $_POST ) ) {
[1068] Fix | Delete
$return = media_upload_form_handler();
[1069] Fix | Delete
[1070] Fix | Delete
if ( is_string( $return ) ) {
[1071] Fix | Delete
return $return;
[1072] Fix | Delete
}
[1073] Fix | Delete
[1074] Fix | Delete
if ( is_array( $return ) ) {
[1075] Fix | Delete
$errors = $return;
[1076] Fix | Delete
}
[1077] Fix | Delete
}
[1078] Fix | Delete
[1079] Fix | Delete
wp_enqueue_script( 'admin-gallery' );
[1080] Fix | Delete
return wp_iframe( 'media_upload_gallery_form', $errors );
[1081] Fix | Delete
}
[1082] Fix | Delete
[1083] Fix | Delete
/**
[1084] Fix | Delete
* Retrieves the legacy media library form in an iframe.
[1085] Fix | Delete
*
[1086] Fix | Delete
* @since 2.5.0
[1087] Fix | Delete
*
[1088] Fix | Delete
* @return string|null
[1089] Fix | Delete
*/
[1090] Fix | Delete
function media_upload_library() {
[1091] Fix | Delete
$errors = array();
[1092] Fix | Delete
[1093] Fix | Delete
if ( ! empty( $_POST ) ) {
[1094] Fix | Delete
$return = media_upload_form_handler();
[1095] Fix | Delete
[1096] Fix | Delete
if ( is_string( $return ) ) {
[1097] Fix | Delete
return $return;
[1098] Fix | Delete
}
[1099] Fix | Delete
if ( is_array( $return ) ) {
[1100] Fix | Delete
$errors = $return;
[1101] Fix | Delete
}
[1102] Fix | Delete
}
[1103] Fix | Delete
[1104] Fix | Delete
return wp_iframe( 'media_upload_library_form', $errors );
[1105] Fix | Delete
}
[1106] Fix | Delete
[1107] Fix | Delete
/**
[1108] Fix | Delete
* Retrieve HTML for the image alignment radio buttons with the specified one checked.
[1109] Fix | Delete
*
[1110] Fix | Delete
* @since 2.7.0
[1111] Fix | Delete
*
[1112] Fix | Delete
* @param WP_Post $post
[1113] Fix | Delete
* @param string $checked
[1114] Fix | Delete
* @return string
[1115] Fix | Delete
*/
[1116] Fix | Delete
function image_align_input_fields( $post, $checked = '' ) {
[1117] Fix | Delete
[1118] Fix | Delete
if ( empty( $checked ) ) {
[1119] Fix | Delete
$checked = get_user_setting( 'align', 'none' );
[1120] Fix | Delete
}
[1121] Fix | Delete
[1122] Fix | Delete
$alignments = array(
[1123] Fix | Delete
'none' => __( 'None' ),
[1124] Fix | Delete
'left' => __( 'Left' ),
[1125] Fix | Delete
'center' => __( 'Center' ),
[1126] Fix | Delete
'right' => __( 'Right' ),
[1127] Fix | Delete
);
[1128] Fix | Delete
[1129] Fix | Delete
if ( ! array_key_exists( (string) $checked, $alignments ) ) {
[1130] Fix | Delete
$checked = 'none';
[1131] Fix | Delete
}
[1132] Fix | Delete
[1133] Fix | Delete
$out = array();
[1134] Fix | Delete
[1135] Fix | Delete
foreach ( $alignments as $name => $label ) {
[1136] Fix | Delete
$name = esc_attr( $name );
[1137] Fix | Delete
$out[] = "<input type='radio' name='attachments[{$post->ID}][align]' id='image-align-{$name}-{$post->ID}' value='$name'" .
[1138] Fix | Delete
( $checked == $name ? " checked='checked'" : '' ) .
[1139] Fix | Delete
" /><label for='image-align-{$name}-{$post->ID}' class='align image-align-{$name}-label'>$label</label>";
[1140] Fix | Delete
}
[1141] Fix | Delete
[1142] Fix | Delete
return implode( "\n", $out );
[1143] Fix | Delete
}
[1144] Fix | Delete
[1145] Fix | Delete
/**
[1146] Fix | Delete
* Retrieve HTML for the size radio buttons with the specified one checked.
[1147] Fix | Delete
*
[1148] Fix | Delete
* @since 2.7.0
[1149] Fix | Delete
*
[1150] Fix | Delete
* @param WP_Post $post
[1151] Fix | Delete
* @param bool|string $check
[1152] Fix | Delete
* @return array
[1153] Fix | Delete
*/
[1154] Fix | Delete
function image_size_input_fields( $post, $check = '' ) {
[1155] Fix | Delete
/**
[1156] Fix | Delete
* Filters the names and labels of the default image sizes.
[1157] Fix | Delete
*
[1158] Fix | Delete
* @since 3.3.0
[1159] Fix | Delete
*
[1160] Fix | Delete
* @param string[] $size_names Array of image size labels keyed by their name. Default values
[1161] Fix | Delete
* include 'Thumbnail', 'Medium', 'Large', and 'Full Size'.
[1162] Fix | Delete
*/
[1163] Fix | Delete
$size_names = apply_filters(
[1164] Fix | Delete
'image_size_names_choose',
[1165] Fix | Delete
array(
[1166] Fix | Delete
'thumbnail' => __( 'Thumbnail' ),
[1167] Fix | Delete
'medium' => __( 'Medium' ),
[1168] Fix | Delete
'large' => __( 'Large' ),
[1169] Fix | Delete
'full' => __( 'Full Size' ),
[1170] Fix | Delete
)
[1171] Fix | Delete
);
[1172] Fix | Delete
[1173] Fix | Delete
if ( empty( $check ) ) {
[1174] Fix | Delete
$check = get_user_setting( 'imgsize', 'medium' );
[1175] Fix | Delete
}
[1176] Fix | Delete
[1177] Fix | Delete
$out = array();
[1178] Fix | Delete
[1179] Fix | Delete
foreach ( $size_names as $size => $label ) {
[1180] Fix | Delete
$downsize = image_downsize( $post->ID, $size );
[1181] Fix | Delete
$checked = '';
[1182] Fix | Delete
[1183] Fix | Delete
// Is this size selectable?
[1184] Fix | Delete
$enabled = ( $downsize[3] || 'full' === $size );
[1185] Fix | Delete
$css_id = "image-size-{$size}-{$post->ID}";
[1186] Fix | Delete
[1187] Fix | Delete
// If this size is the default but that's not available, don't select it.
[1188] Fix | Delete
if ( $size == $check ) {
[1189] Fix | Delete
if ( $enabled ) {
[1190] Fix | Delete
$checked = " checked='checked'";
[1191] Fix | Delete
} else {
[1192] Fix | Delete
$check = '';
[1193] Fix | Delete
}
[1194] Fix | Delete
} elseif ( ! $check && $enabled && 'thumbnail' !== $size ) {
[1195] Fix | Delete
/*
[1196] Fix | Delete
* If $check is not enabled, default to the first available size
[1197] Fix | Delete
* that's bigger than a thumbnail.
[1198] Fix | Delete
*/
[1199] Fix | Delete
$check = $size;
[1200] Fix | Delete
$checked = " checked='checked'";
[1201] Fix | Delete
}
[1202] Fix | Delete
[1203] Fix | Delete
$html = "<div class='image-size-item'><input type='radio' " . disabled( $enabled, false, false ) . "name='attachments[$post->ID][image-size]' id='{$css_id}' value='{$size}'$checked />";
[1204] Fix | Delete
[1205] Fix | Delete
$html .= "<label for='{$css_id}'>$label</label>";
[1206] Fix | Delete
[1207] Fix | Delete
// Only show the dimensions if that choice is available.
[1208] Fix | Delete
if ( $enabled ) {
[1209] Fix | Delete
$html .= " <label for='{$css_id}' class='help'>" . sprintf( '(%d&nbsp;&times;&nbsp;%d)', $downsize[1], $downsize[2] ) . '</label>';
[1210] Fix | Delete
}
[1211] Fix | Delete
$html .= '</div>';
[1212] Fix | Delete
[1213] Fix | Delete
$out[] = $html;
[1214] Fix | Delete
}
[1215] Fix | Delete
[1216] Fix | Delete
return array(
[1217] Fix | Delete
'label' => __( 'Size' ),
[1218] Fix | Delete
'input' => 'html',
[1219] Fix | Delete
'html' => implode( "\n", $out ),
[1220] Fix | Delete
);
[1221] Fix | Delete
}
[1222] Fix | Delete
[1223] Fix | Delete
/**
[1224] Fix | Delete
* Retrieve HTML for the Link URL buttons with the default link type as specified.
[1225] Fix | Delete
*
[1226] Fix | Delete
* @since 2.7.0
[1227] Fix | Delete
*
[1228] Fix | Delete
* @param WP_Post $post
[1229] Fix | Delete
* @param string $url_type
[1230] Fix | Delete
* @return string
[1231] Fix | Delete
*/
[1232] Fix | Delete
function image_link_input_fields( $post, $url_type = '' ) {
[1233] Fix | Delete
[1234] Fix | Delete
$file = wp_get_attachment_url( $post->ID );
[1235] Fix | Delete
$link = get_attachment_link( $post->ID );
[1236] Fix | Delete
[1237] Fix | Delete
if ( empty( $url_type ) ) {
[1238] Fix | Delete
$url_type = get_user_setting( 'urlbutton', 'post' );
[1239] Fix | Delete
}
[1240] Fix | Delete
[1241] Fix | Delete
$url = '';
[1242] Fix | Delete
[1243] Fix | Delete
if ( 'file' === $url_type ) {
[1244] Fix | Delete
$url = $file;
[1245] Fix | Delete
} elseif ( 'post' === $url_type ) {
[1246] Fix | Delete
$url = $link;
[1247] Fix | Delete
}
[1248] Fix | Delete
[1249] Fix | Delete
return "
[1250] Fix | Delete
<input type='text' class='text urlfield' name='attachments[$post->ID][url]' value='" . esc_attr( $url ) . "' /><br />
[1251] Fix | Delete
<button type='button' class='button urlnone' data-link-url=''>" . __( 'None' ) . "</button>
[1252] Fix | Delete
<button type='button' class='button urlfile' data-link-url='" . esc_attr( $file ) . "'>" . __( 'File URL' ) . "</button>
[1253] Fix | Delete
<button type='button' class='button urlpost' data-link-url='" . esc_attr( $link ) . "'>" . __( 'Attachment Post URL' ) . '</button>
[1254] Fix | Delete
';
[1255] Fix | Delete
}
[1256] Fix | Delete
[1257] Fix | Delete
/**
[1258] Fix | Delete
* Output a textarea element for inputting an attachment caption.
[1259] Fix | Delete
*
[1260] Fix | Delete
* @since 3.4.0
[1261] Fix | Delete
*
[1262] Fix | Delete
* @param WP_Post $edit_post Attachment WP_Post object.
[1263] Fix | Delete
* @return string HTML markup for the textarea element.
[1264] Fix | Delete
*/
[1265] Fix | Delete
function wp_caption_input_textarea( $edit_post ) {
[1266] Fix | Delete
// Post data is already escaped.
[1267] Fix | Delete
$name = "attachments[{$edit_post->ID}][post_excerpt]";
[1268] Fix | Delete
[1269] Fix | Delete
return '<textarea name="' . $name . '" id="' . $name . '">' . $edit_post->post_excerpt . '</textarea>';
[1270] Fix | Delete
}
[1271] Fix | Delete
[1272] Fix | Delete
/**
[1273] Fix | Delete
* Retrieves the image attachment fields to edit form fields.
[1274] Fix | Delete
*
[1275] Fix | Delete
* @since 2.5.0
[1276] Fix | Delete
*
[1277] Fix | Delete
* @param array $form_fields
[1278] Fix | Delete
* @param object $post
[1279] Fix | Delete
* @return array
[1280] Fix | Delete
*/
[1281] Fix | Delete
function image_attachment_fields_to_edit( $form_fields, $post ) {
[1282] Fix | Delete
return $form_fields;
[1283] Fix | Delete
}
[1284] Fix | Delete
[1285] Fix | Delete
/**
[1286] Fix | Delete
* Retrieves the single non-image attachment fields to edit form fields.
[1287] Fix | Delete
*
[1288] Fix | Delete
* @since 2.5.0
[1289] Fix | Delete
*
[1290] Fix | Delete
* @param array $form_fields An array of attachment form fields.
[1291] Fix | Delete
* @param WP_Post $post The WP_Post attachment object.
[1292] Fix | Delete
* @return array Filtered attachment form fields.
[1293] Fix | Delete
*/
[1294] Fix | Delete
function media_single_attachment_fields_to_edit( $form_fields, $post ) {
[1295] Fix | Delete
unset( $form_fields['url'], $form_fields['align'], $form_fields['image-size'] );
[1296] Fix | Delete
return $form_fields;
[1297] Fix | Delete
}
[1298] Fix | Delete
[1299] Fix | Delete
/**
[1300] Fix | Delete
* Retrieves the post non-image attachment fields to edit form fields.
[1301] Fix | Delete
*
[1302] Fix | Delete
* @since 2.8.0
[1303] Fix | Delete
*
[1304] Fix | Delete
* @param array $form_fields An array of attachment form fields.
[1305] Fix | Delete
* @param WP_Post $post The WP_Post attachment object.
[1306] Fix | Delete
* @return array Filtered attachment form fields.
[1307] Fix | Delete
*/
[1308] Fix | Delete
function media_post_single_attachment_fields_to_edit( $form_fields, $post ) {
[1309] Fix | Delete
unset( $form_fields['image_url'] );
[1310] Fix | Delete
return $form_fields;
[1311] Fix | Delete
}
[1312] Fix | Delete
[1313] Fix | Delete
/**
[1314] Fix | Delete
* Filters input from media_upload_form_handler() and assigns a default
[1315] Fix | Delete
* post_title from the file name if none supplied.
[1316] Fix | Delete
*
[1317] Fix | Delete
* Illustrates the use of the {@see 'attachment_fields_to_save'} filter
[1318] Fix | Delete
* which can be used to add default values to any field before saving to DB.
[1319] Fix | Delete
*
[1320] Fix | Delete
* @since 2.5.0
[1321] Fix | Delete
*
[1322] Fix | Delete
* @param array $post The WP_Post attachment object converted to an array.
[1323] Fix | Delete
* @param array $attachment An array of attachment metadata.
[1324] Fix | Delete
* @return array Filtered attachment post object.
[1325] Fix | Delete
*/
[1326] Fix | Delete
function image_attachment_fields_to_save( $post, $attachment ) {
[1327] Fix | Delete
if ( 'image' === substr( $post['post_mime_type'], 0, 5 ) ) {
[1328] Fix | Delete
if ( strlen( trim( $post['post_title'] ) ) == 0 ) {
[1329] Fix | Delete
$attachment_url = ( isset( $post['attachment_url'] ) ) ? $post['attachment_url'] : $post['guid'];
[1330] Fix | Delete
$post['post_title'] = preg_replace( '/\.\w+$/', '', wp_basename( $attachment_url ) );
[1331] Fix | Delete
$post['errors']['post_title']['errors'][] = __( 'Empty Title filled from filename.' );
[1332] Fix | Delete
}
[1333] Fix | Delete
}
[1334] Fix | Delete
[1335] Fix | Delete
return $post;
[1336] Fix | Delete
}
[1337] Fix | Delete
[1338] Fix | Delete
/**
[1339] Fix | Delete
* Retrieves the media element HTML to send to the editor.
[1340] Fix | Delete
*
[1341] Fix | Delete
* @since 2.5.0
[1342] Fix | Delete
*
[1343] Fix | Delete
* @param string $html
[1344] Fix | Delete
* @param int $attachment_id
[1345] Fix | Delete
* @param array $attachment
[1346] Fix | Delete
* @return string
[1347] Fix | Delete
*/
[1348] Fix | Delete
function image_media_send_to_editor( $html, $attachment_id, $attachment ) {
[1349] Fix | Delete
$post = get_post( $attachment_id );
[1350] Fix | Delete
[1351] Fix | Delete
if ( 'image' === substr( $post->post_mime_type, 0, 5 ) ) {
[1352] Fix | Delete
$url = $attachment['url'];
[1353] Fix | Delete
$align = ! empty( $attachment['align'] ) ? $attachment['align'] : 'none';
[1354] Fix | Delete
$size = ! empty( $attachment['image-size'] ) ? $attachment['image-size'] : 'medium';
[1355] Fix | Delete
$alt = ! empty( $attachment['image_alt'] ) ? $attachment['image_alt'] : '';
[1356] Fix | Delete
$rel = ( strpos( $url, 'attachment_id' ) || get_attachment_link( $attachment_id ) === $url );
[1357] Fix | Delete
[1358] Fix | Delete
return get_image_send_to_editor( $attachment_id, $attachment['post_excerpt'], $attachment['post_title'], $align, $url, $rel, $size, $alt );
[1359] Fix | Delete
}
[1360] Fix | Delete
[1361] Fix | Delete
return $html;
[1362] Fix | Delete
}
[1363] Fix | Delete
[1364] Fix | Delete
/**
[1365] Fix | Delete
* Retrieves the attachment fields to edit form fields.
[1366] Fix | Delete
*
[1367] Fix | Delete
* @since 2.5.0
[1368] Fix | Delete
*
[1369] Fix | Delete
* @param WP_Post $post
[1370] Fix | Delete
* @param array $errors
[1371] Fix | Delete
* @return array
[1372] Fix | Delete
*/
[1373] Fix | Delete
function get_attachment_fields_to_edit( $post, $errors = null ) {
[1374] Fix | Delete
if ( is_int( $post ) ) {
[1375] Fix | Delete
$post = get_post( $post );
[1376] Fix | Delete
}
[1377] Fix | Delete
[1378] Fix | Delete
if ( is_array( $post ) ) {
[1379] Fix | Delete
$post = new WP_Post( (object) $post );
[1380] Fix | Delete
}
[1381] Fix | Delete
[1382] Fix | Delete
$image_url = wp_get_attachment_url( $post->ID );
[1383] Fix | Delete
[1384] Fix | Delete
$edit_post = sanitize_post( $post, 'edit' );
[1385] Fix | Delete
[1386] Fix | Delete
$form_fields = array(
[1387] Fix | Delete
'post_title' => array(
[1388] Fix | Delete
'label' => __( 'Title' ),
[1389] Fix | Delete
'value' => $edit_post->post_title,
[1390] Fix | Delete
),
[1391] Fix | Delete
'image_alt' => array(),
[1392] Fix | Delete
'post_excerpt' => array(
[1393] Fix | Delete
'label' => __( 'Caption' ),
[1394] Fix | Delete
'input' => 'html',
[1395] Fix | Delete
'html' => wp_caption_input_textarea( $edit_post ),
[1396] Fix | Delete
),
[1397] Fix | Delete
'post_content' => array(
[1398] Fix | Delete
'label' => __( 'Description' ),
[1399] Fix | Delete
'value' => $edit_post->post_content,
[1400] Fix | Delete
'input' => 'textarea',
[1401] Fix | Delete
),
[1402] Fix | Delete
'url' => array(
[1403] Fix | Delete
'label' => __( 'Link URL' ),
[1404] Fix | Delete
'input' => 'html',
[1405] Fix | Delete
'html' => image_link_input_fields( $post, get_option( 'image_default_link_type' ) ),
[1406] Fix | Delete
'helps' => __( 'Enter a link URL or click above for presets.' ),
[1407] Fix | Delete
),
[1408] Fix | Delete
'menu_order' => array(
[1409] Fix | Delete
'label' => __( 'Order' ),
[1410] Fix | Delete
'value' => $edit_post->menu_order,
[1411] Fix | Delete
),
[1412] Fix | Delete
'image_url' => array(
[1413] Fix | Delete
'label' => __( 'File URL' ),
[1414] Fix | Delete
'input' => 'html',
[1415] Fix | Delete
'html' => "<input type='text' class='text urlfield' readonly='readonly' name='attachments[$post->ID][url]' value='" . esc_attr( $image_url ) . "' /><br />",
[1416] Fix | Delete
'value' => wp_get_attachment_url( $post->ID ),
[1417] Fix | Delete
'helps' => __( 'Location of the uploaded file.' ),
[1418] Fix | Delete
),
[1419] Fix | Delete
);
[1420] Fix | Delete
[1421] Fix | Delete
foreach ( get_attachment_taxonomies( $post ) as $taxonomy ) {
[1422] Fix | Delete
$t = (array) get_taxonomy( $taxonomy );
[1423] Fix | Delete
[1424] Fix | Delete
if ( ! $t['public'] || ! $t['show_ui'] ) {
[1425] Fix | Delete
continue;
[1426] Fix | Delete
}
[1427] Fix | Delete
[1428] Fix | Delete
if ( empty( $t['label'] ) ) {
[1429] Fix | Delete
$t['label'] = $taxonomy;
[1430] Fix | Delete
}
[1431] Fix | Delete
[1432] Fix | Delete
if ( empty( $t['args'] ) ) {
[1433] Fix | Delete
$t['args'] = array();
[1434] Fix | Delete
}
[1435] Fix | Delete
[1436] Fix | Delete
$terms = get_object_term_cache( $post->ID, $taxonomy );
[1437] Fix | Delete
[1438] Fix | Delete
if ( false === $terms ) {
[1439] Fix | Delete
$terms = wp_get_object_terms( $post->ID, $taxonomy, $t['args'] );
[1440] Fix | Delete
}
[1441] Fix | Delete
[1442] Fix | Delete
$values = array();
[1443] Fix | Delete
[1444] Fix | Delete
foreach ( $terms as $term ) {
[1445] Fix | Delete
$values[] = $term->slug;
[1446] Fix | Delete
}
[1447] Fix | Delete
[1448] Fix | Delete
$t['value'] = implode( ', ', $values );
[1449] Fix | Delete
[1450] Fix | Delete
$form_fields[ $taxonomy ] = $t;
[1451] Fix | Delete
}
[1452] Fix | Delete
[1453] Fix | Delete
/*
[1454] Fix | Delete
* Merge default fields with their errors, so any key passed with the error
[1455] Fix | Delete
* (e.g. 'error', 'helps', 'value') will replace the default.
[1456] Fix | Delete
* The recursive merge is easily traversed with array casting:
[1457] Fix | Delete
* foreach ( (array) $things as $thing )
[1458] Fix | Delete
*/
[1459] Fix | Delete
$form_fields = array_merge_recursive( $form_fields, (array) $errors );
[1460] Fix | Delete
[1461] Fix | Delete
// This was formerly in image_attachment_fields_to_edit().
[1462] Fix | Delete
if ( 'image' === substr( $post->post_mime_type, 0, 5 ) ) {
[1463] Fix | Delete
$alt = get_post_meta( $post->ID, '_wp_attachment_image_alt', true );
[1464] Fix | Delete
[1465] Fix | Delete
if ( empty( $alt ) ) {
[1466] Fix | Delete
$alt = '';
[1467] Fix | Delete
}
[1468] Fix | Delete
[1469] Fix | Delete
$form_fields['post_title']['required'] = true;
[1470] Fix | Delete
[1471] Fix | Delete
$form_fields['image_alt'] = array(
[1472] Fix | Delete
'value' => $alt,
[1473] Fix | Delete
'label' => __( 'Alternative Text' ),
[1474] Fix | Delete
'helps' => __( 'Alt text for the image, e.g. &#8220;The Mona Lisa&#8221;' ),
[1475] Fix | Delete
);
[1476] Fix | Delete
[1477] Fix | Delete
$form_fields['align'] = array(
[1478] Fix | Delete
'label' => __( 'Alignment' ),
[1479] Fix | Delete
'input' => 'html',
[1480] Fix | Delete
'html' => image_align_input_fields( $post, get_option( 'image_default_align' ) ),
[1481] Fix | Delete
);
[1482] Fix | Delete
[1483] Fix | Delete
$form_fields['image-size'] = image_size_input_fields( $post, get_option( 'image_default_size', 'medium' ) );
[1484] Fix | Delete
[1485] Fix | Delete
} else {
[1486] Fix | Delete
unset( $form_fields['image_alt'] );
[1487] Fix | Delete
}
[1488] Fix | Delete
[1489] Fix | Delete
/**
[1490] Fix | Delete
* Filters the attachment fields to edit.
[1491] Fix | Delete
*
[1492] Fix | Delete
* @since 2.5.0
[1493] Fix | Delete
*
[1494] Fix | Delete
* @param array $form_fields An array of attachment form fields.
[1495] Fix | Delete
* @param WP_Post $post The WP_Post attachment object.
[1496] Fix | Delete
*/
[1497] Fix | Delete
$form_fields = apply_filters( 'attachment_fields_to_edit', $form_fields, $post );
[1498] Fix | Delete
[1499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function