Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93

Warning: Undefined array key "page_file_edit_line" in /home/sportsfever/public_html/filemanger/edit_text_line.php on line 32
/home/sportsfe.../www/clone/wp-admin/includes
File: class-custom-image-header.php
);
[1000] Fix | Delete
[1001] Fix | Delete
// Save the data.
[1002] Fix | Delete
$attachment_id = wp_insert_attachment( $attachment, $file );
[1003] Fix | Delete
[1004] Fix | Delete
return compact( 'attachment_id', 'file', 'filename', 'url', 'type' );
[1005] Fix | Delete
}
[1006] Fix | Delete
[1007] Fix | Delete
/**
[1008] Fix | Delete
* Displays third step of custom header image page.
[1009] Fix | Delete
*
[1010] Fix | Delete
* @since 2.1.0
[1011] Fix | Delete
* @since 4.4.0 Switched to using wp_get_attachment_url() instead of the guid
[1012] Fix | Delete
* for retrieving the header image URL.
[1013] Fix | Delete
*/
[1014] Fix | Delete
public function step_3() {
[1015] Fix | Delete
check_admin_referer( 'custom-header-crop-image' );
[1016] Fix | Delete
[1017] Fix | Delete
if ( ! current_theme_supports( 'custom-header', 'uploads' ) ) {
[1018] Fix | Delete
wp_die(
[1019] Fix | Delete
'<h1>' . __( 'Something went wrong.' ) . '</h1>' .
[1020] Fix | Delete
'<p>' . __( 'The active theme does not support uploading a custom header image.' ) . '</p>',
[1021] Fix | Delete
403
[1022] Fix | Delete
);
[1023] Fix | Delete
}
[1024] Fix | Delete
[1025] Fix | Delete
if ( ! empty( $_POST['skip-cropping'] )
[1026] Fix | Delete
&& ! current_theme_supports( 'custom-header', 'flex-height' )
[1027] Fix | Delete
&& ! current_theme_supports( 'custom-header', 'flex-width' )
[1028] Fix | Delete
) {
[1029] Fix | Delete
wp_die(
[1030] Fix | Delete
'<h1>' . __( 'Something went wrong.' ) . '</h1>' .
[1031] Fix | Delete
'<p>' . __( 'The active theme does not support a flexible sized header image.' ) . '</p>',
[1032] Fix | Delete
403
[1033] Fix | Delete
);
[1034] Fix | Delete
}
[1035] Fix | Delete
[1036] Fix | Delete
if ( $_POST['oitar'] > 1 ) {
[1037] Fix | Delete
$_POST['x1'] = $_POST['x1'] * $_POST['oitar'];
[1038] Fix | Delete
$_POST['y1'] = $_POST['y1'] * $_POST['oitar'];
[1039] Fix | Delete
$_POST['width'] = $_POST['width'] * $_POST['oitar'];
[1040] Fix | Delete
$_POST['height'] = $_POST['height'] * $_POST['oitar'];
[1041] Fix | Delete
}
[1042] Fix | Delete
[1043] Fix | Delete
$attachment_id = absint( $_POST['attachment_id'] );
[1044] Fix | Delete
$original = get_attached_file( $attachment_id );
[1045] Fix | Delete
[1046] Fix | Delete
$dimensions = $this->get_header_dimensions(
[1047] Fix | Delete
array(
[1048] Fix | Delete
'height' => $_POST['height'],
[1049] Fix | Delete
'width' => $_POST['width'],
[1050] Fix | Delete
)
[1051] Fix | Delete
);
[1052] Fix | Delete
$height = $dimensions['dst_height'];
[1053] Fix | Delete
$width = $dimensions['dst_width'];
[1054] Fix | Delete
[1055] Fix | Delete
if ( empty( $_POST['skip-cropping'] ) ) {
[1056] Fix | Delete
$cropped = wp_crop_image(
[1057] Fix | Delete
$attachment_id,
[1058] Fix | Delete
(int) $_POST['x1'],
[1059] Fix | Delete
(int) $_POST['y1'],
[1060] Fix | Delete
(int) $_POST['width'],
[1061] Fix | Delete
(int) $_POST['height'],
[1062] Fix | Delete
$width,
[1063] Fix | Delete
$height
[1064] Fix | Delete
);
[1065] Fix | Delete
} elseif ( ! empty( $_POST['create-new-attachment'] ) ) {
[1066] Fix | Delete
$cropped = _copy_image_file( $attachment_id );
[1067] Fix | Delete
} else {
[1068] Fix | Delete
$cropped = get_attached_file( $attachment_id );
[1069] Fix | Delete
}
[1070] Fix | Delete
[1071] Fix | Delete
if ( ! $cropped || is_wp_error( $cropped ) ) {
[1072] Fix | Delete
wp_die( __( 'Image could not be processed. Please go back and try again.' ), __( 'Image Processing Error' ) );
[1073] Fix | Delete
}
[1074] Fix | Delete
[1075] Fix | Delete
/** This filter is documented in wp-admin/includes/class-custom-image-header.php */
[1076] Fix | Delete
$cropped = apply_filters( 'wp_create_file_in_uploads', $cropped, $attachment_id ); // For replication.
[1077] Fix | Delete
[1078] Fix | Delete
$attachment = wp_copy_parent_attachment_properties( $cropped, $attachment_id, 'custom-header' );
[1079] Fix | Delete
[1080] Fix | Delete
if ( ! empty( $_POST['create-new-attachment'] ) ) {
[1081] Fix | Delete
unset( $attachment['ID'] );
[1082] Fix | Delete
}
[1083] Fix | Delete
[1084] Fix | Delete
// Update the attachment.
[1085] Fix | Delete
$attachment_id = $this->insert_attachment( $attachment, $cropped );
[1086] Fix | Delete
[1087] Fix | Delete
$url = wp_get_attachment_url( $attachment_id );
[1088] Fix | Delete
$this->set_header_image( compact( 'url', 'attachment_id', 'width', 'height' ) );
[1089] Fix | Delete
[1090] Fix | Delete
// Cleanup.
[1091] Fix | Delete
$medium = str_replace( wp_basename( $original ), 'midsize-' . wp_basename( $original ), $original );
[1092] Fix | Delete
if ( file_exists( $medium ) ) {
[1093] Fix | Delete
wp_delete_file( $medium );
[1094] Fix | Delete
}
[1095] Fix | Delete
[1096] Fix | Delete
if ( empty( $_POST['create-new-attachment'] ) && empty( $_POST['skip-cropping'] ) ) {
[1097] Fix | Delete
wp_delete_file( $original );
[1098] Fix | Delete
}
[1099] Fix | Delete
[1100] Fix | Delete
return $this->finished();
[1101] Fix | Delete
}
[1102] Fix | Delete
[1103] Fix | Delete
/**
[1104] Fix | Delete
* Displays last step of custom header image page.
[1105] Fix | Delete
*
[1106] Fix | Delete
* @since 2.1.0
[1107] Fix | Delete
*/
[1108] Fix | Delete
public function finished() {
[1109] Fix | Delete
$this->updated = true;
[1110] Fix | Delete
$this->step_1();
[1111] Fix | Delete
}
[1112] Fix | Delete
[1113] Fix | Delete
/**
[1114] Fix | Delete
* Displays the page based on the current step.
[1115] Fix | Delete
*
[1116] Fix | Delete
* @since 2.1.0
[1117] Fix | Delete
*/
[1118] Fix | Delete
public function admin_page() {
[1119] Fix | Delete
if ( ! current_user_can( 'edit_theme_options' ) ) {
[1120] Fix | Delete
wp_die( __( 'Sorry, you are not allowed to customize headers.' ) );
[1121] Fix | Delete
}
[1122] Fix | Delete
[1123] Fix | Delete
$step = $this->step();
[1124] Fix | Delete
[1125] Fix | Delete
if ( 2 === $step ) {
[1126] Fix | Delete
$this->step_2();
[1127] Fix | Delete
} elseif ( 3 === $step ) {
[1128] Fix | Delete
$this->step_3();
[1129] Fix | Delete
} else {
[1130] Fix | Delete
$this->step_1();
[1131] Fix | Delete
}
[1132] Fix | Delete
}
[1133] Fix | Delete
[1134] Fix | Delete
/**
[1135] Fix | Delete
* Unused since 3.5.0.
[1136] Fix | Delete
*
[1137] Fix | Delete
* @since 3.4.0
[1138] Fix | Delete
*
[1139] Fix | Delete
* @param array $form_fields
[1140] Fix | Delete
* @return array $form_fields
[1141] Fix | Delete
*/
[1142] Fix | Delete
public function attachment_fields_to_edit( $form_fields ) {
[1143] Fix | Delete
return $form_fields;
[1144] Fix | Delete
}
[1145] Fix | Delete
[1146] Fix | Delete
/**
[1147] Fix | Delete
* Unused since 3.5.0.
[1148] Fix | Delete
*
[1149] Fix | Delete
* @since 3.4.0
[1150] Fix | Delete
*
[1151] Fix | Delete
* @param array $tabs
[1152] Fix | Delete
* @return array $tabs
[1153] Fix | Delete
*/
[1154] Fix | Delete
public function filter_upload_tabs( $tabs ) {
[1155] Fix | Delete
return $tabs;
[1156] Fix | Delete
}
[1157] Fix | Delete
[1158] Fix | Delete
/**
[1159] Fix | Delete
* Chooses a header image, selected from existing uploaded and default headers,
[1160] Fix | Delete
* or provides an array of uploaded header data (either new, or from media library).
[1161] Fix | Delete
*
[1162] Fix | Delete
* @since 3.4.0
[1163] Fix | Delete
*
[1164] Fix | Delete
* @param mixed $choice Which header image to select. Allows for values of 'random-default-image',
[1165] Fix | Delete
* for randomly cycling among the default images; 'random-uploaded-image',
[1166] Fix | Delete
* for randomly cycling among the uploaded images; the key of a default image
[1167] Fix | Delete
* registered for that theme; and the key of an image uploaded for that theme
[1168] Fix | Delete
* (the attachment ID of the image). Or an array of arguments: attachment_id,
[1169] Fix | Delete
* url, width, height. All are required.
[1170] Fix | Delete
*/
[1171] Fix | Delete
final public function set_header_image( $choice ) {
[1172] Fix | Delete
if ( is_array( $choice ) || is_object( $choice ) ) {
[1173] Fix | Delete
$choice = (array) $choice;
[1174] Fix | Delete
[1175] Fix | Delete
if ( ! isset( $choice['attachment_id'] ) || ! isset( $choice['url'] ) ) {
[1176] Fix | Delete
return;
[1177] Fix | Delete
}
[1178] Fix | Delete
[1179] Fix | Delete
$choice['url'] = sanitize_url( $choice['url'] );
[1180] Fix | Delete
[1181] Fix | Delete
$header_image_data = (object) array(
[1182] Fix | Delete
'attachment_id' => $choice['attachment_id'],
[1183] Fix | Delete
'url' => $choice['url'],
[1184] Fix | Delete
'thumbnail_url' => $choice['url'],
[1185] Fix | Delete
'height' => $choice['height'],
[1186] Fix | Delete
'width' => $choice['width'],
[1187] Fix | Delete
);
[1188] Fix | Delete
[1189] Fix | Delete
update_post_meta( $choice['attachment_id'], '_wp_attachment_is_custom_header', get_stylesheet() );
[1190] Fix | Delete
[1191] Fix | Delete
set_theme_mod( 'header_image', $choice['url'] );
[1192] Fix | Delete
set_theme_mod( 'header_image_data', $header_image_data );
[1193] Fix | Delete
[1194] Fix | Delete
return;
[1195] Fix | Delete
}
[1196] Fix | Delete
[1197] Fix | Delete
if ( in_array( $choice, array( 'remove-header', 'random-default-image', 'random-uploaded-image' ), true ) ) {
[1198] Fix | Delete
set_theme_mod( 'header_image', $choice );
[1199] Fix | Delete
remove_theme_mod( 'header_image_data' );
[1200] Fix | Delete
[1201] Fix | Delete
return;
[1202] Fix | Delete
}
[1203] Fix | Delete
[1204] Fix | Delete
$uploaded = get_uploaded_header_images();
[1205] Fix | Delete
[1206] Fix | Delete
if ( $uploaded && isset( $uploaded[ $choice ] ) ) {
[1207] Fix | Delete
$header_image_data = $uploaded[ $choice ];
[1208] Fix | Delete
} else {
[1209] Fix | Delete
$this->process_default_headers();
[1210] Fix | Delete
if ( isset( $this->default_headers[ $choice ] ) ) {
[1211] Fix | Delete
$header_image_data = $this->default_headers[ $choice ];
[1212] Fix | Delete
} else {
[1213] Fix | Delete
return;
[1214] Fix | Delete
}
[1215] Fix | Delete
}
[1216] Fix | Delete
[1217] Fix | Delete
set_theme_mod( 'header_image', sanitize_url( $header_image_data['url'] ) );
[1218] Fix | Delete
set_theme_mod( 'header_image_data', $header_image_data );
[1219] Fix | Delete
}
[1220] Fix | Delete
[1221] Fix | Delete
/**
[1222] Fix | Delete
* Removes a header image.
[1223] Fix | Delete
*
[1224] Fix | Delete
* @since 3.4.0
[1225] Fix | Delete
*/
[1226] Fix | Delete
final public function remove_header_image() {
[1227] Fix | Delete
$this->set_header_image( 'remove-header' );
[1228] Fix | Delete
}
[1229] Fix | Delete
[1230] Fix | Delete
/**
[1231] Fix | Delete
* Resets a header image to the default image for the theme.
[1232] Fix | Delete
*
[1233] Fix | Delete
* This method does not do anything if the theme does not have a default header image.
[1234] Fix | Delete
*
[1235] Fix | Delete
* @since 3.4.0
[1236] Fix | Delete
*/
[1237] Fix | Delete
final public function reset_header_image() {
[1238] Fix | Delete
$this->process_default_headers();
[1239] Fix | Delete
$default = get_theme_support( 'custom-header', 'default-image' );
[1240] Fix | Delete
[1241] Fix | Delete
if ( ! $default ) {
[1242] Fix | Delete
$this->remove_header_image();
[1243] Fix | Delete
return;
[1244] Fix | Delete
}
[1245] Fix | Delete
[1246] Fix | Delete
$default = sprintf( $default, get_template_directory_uri(), get_stylesheet_directory_uri() );
[1247] Fix | Delete
[1248] Fix | Delete
$default_data = array();
[1249] Fix | Delete
foreach ( $this->default_headers as $header => $details ) {
[1250] Fix | Delete
if ( $details['url'] === $default ) {
[1251] Fix | Delete
$default_data = $details;
[1252] Fix | Delete
break;
[1253] Fix | Delete
}
[1254] Fix | Delete
}
[1255] Fix | Delete
[1256] Fix | Delete
set_theme_mod( 'header_image', $default );
[1257] Fix | Delete
set_theme_mod( 'header_image_data', (object) $default_data );
[1258] Fix | Delete
}
[1259] Fix | Delete
[1260] Fix | Delete
/**
[1261] Fix | Delete
* Calculates width and height based on what the currently selected theme supports.
[1262] Fix | Delete
*
[1263] Fix | Delete
* @since 3.9.0
[1264] Fix | Delete
*
[1265] Fix | Delete
* @param array $dimensions
[1266] Fix | Delete
* @return array dst_height and dst_width of header image.
[1267] Fix | Delete
*/
[1268] Fix | Delete
final public function get_header_dimensions( $dimensions ) {
[1269] Fix | Delete
$max_width = 0;
[1270] Fix | Delete
$width = absint( $dimensions['width'] );
[1271] Fix | Delete
$height = absint( $dimensions['height'] );
[1272] Fix | Delete
$theme_height = get_theme_support( 'custom-header', 'height' );
[1273] Fix | Delete
$theme_width = get_theme_support( 'custom-header', 'width' );
[1274] Fix | Delete
$has_flex_width = current_theme_supports( 'custom-header', 'flex-width' );
[1275] Fix | Delete
$has_flex_height = current_theme_supports( 'custom-header', 'flex-height' );
[1276] Fix | Delete
$has_max_width = current_theme_supports( 'custom-header', 'max-width' );
[1277] Fix | Delete
$dst = array(
[1278] Fix | Delete
'dst_height' => null,
[1279] Fix | Delete
'dst_width' => null,
[1280] Fix | Delete
);
[1281] Fix | Delete
[1282] Fix | Delete
// For flex, limit size of image displayed to 1500px unless theme says otherwise.
[1283] Fix | Delete
if ( $has_flex_width ) {
[1284] Fix | Delete
$max_width = 1500;
[1285] Fix | Delete
}
[1286] Fix | Delete
[1287] Fix | Delete
if ( $has_max_width ) {
[1288] Fix | Delete
$max_width = max( $max_width, get_theme_support( 'custom-header', 'max-width' ) );
[1289] Fix | Delete
}
[1290] Fix | Delete
$max_width = max( $max_width, $theme_width );
[1291] Fix | Delete
[1292] Fix | Delete
if ( $has_flex_height && ( ! $has_flex_width || $width > $max_width ) ) {
[1293] Fix | Delete
$dst['dst_height'] = absint( $height * ( $max_width / $width ) );
[1294] Fix | Delete
} elseif ( $has_flex_height && $has_flex_width ) {
[1295] Fix | Delete
$dst['dst_height'] = $height;
[1296] Fix | Delete
} else {
[1297] Fix | Delete
$dst['dst_height'] = $theme_height;
[1298] Fix | Delete
}
[1299] Fix | Delete
[1300] Fix | Delete
if ( $has_flex_width && ( ! $has_flex_height || $width > $max_width ) ) {
[1301] Fix | Delete
$dst['dst_width'] = absint( $width * ( $max_width / $width ) );
[1302] Fix | Delete
} elseif ( $has_flex_width && $has_flex_height ) {
[1303] Fix | Delete
$dst['dst_width'] = $width;
[1304] Fix | Delete
} else {
[1305] Fix | Delete
$dst['dst_width'] = $theme_width;
[1306] Fix | Delete
}
[1307] Fix | Delete
[1308] Fix | Delete
return $dst;
[1309] Fix | Delete
}
[1310] Fix | Delete
[1311] Fix | Delete
/**
[1312] Fix | Delete
* Creates an attachment 'object'.
[1313] Fix | Delete
*
[1314] Fix | Delete
* @since 3.9.0
[1315] Fix | Delete
* @deprecated 6.5.0
[1316] Fix | Delete
*
[1317] Fix | Delete
* @param string $cropped Cropped image URL.
[1318] Fix | Delete
* @param int $parent_attachment_id Attachment ID of parent image.
[1319] Fix | Delete
* @return array An array with attachment object data.
[1320] Fix | Delete
*/
[1321] Fix | Delete
final public function create_attachment_object( $cropped, $parent_attachment_id ) {
[1322] Fix | Delete
_deprecated_function( __METHOD__, '6.5.0', 'wp_copy_parent_attachment_properties()' );
[1323] Fix | Delete
$parent = get_post( $parent_attachment_id );
[1324] Fix | Delete
$parent_url = wp_get_attachment_url( $parent->ID );
[1325] Fix | Delete
$url = str_replace( wp_basename( $parent_url ), wp_basename( $cropped ), $parent_url );
[1326] Fix | Delete
[1327] Fix | Delete
$size = wp_getimagesize( $cropped );
[1328] Fix | Delete
$image_type = ( $size ) ? $size['mime'] : 'image/jpeg';
[1329] Fix | Delete
[1330] Fix | Delete
$attachment = array(
[1331] Fix | Delete
'ID' => $parent_attachment_id,
[1332] Fix | Delete
'post_title' => wp_basename( $cropped ),
[1333] Fix | Delete
'post_mime_type' => $image_type,
[1334] Fix | Delete
'guid' => $url,
[1335] Fix | Delete
'context' => 'custom-header',
[1336] Fix | Delete
'post_parent' => $parent_attachment_id,
[1337] Fix | Delete
);
[1338] Fix | Delete
[1339] Fix | Delete
return $attachment;
[1340] Fix | Delete
}
[1341] Fix | Delete
[1342] Fix | Delete
/**
[1343] Fix | Delete
* Inserts an attachment and its metadata.
[1344] Fix | Delete
*
[1345] Fix | Delete
* @since 3.9.0
[1346] Fix | Delete
*
[1347] Fix | Delete
* @param array $attachment An array with attachment object data.
[1348] Fix | Delete
* @param string $cropped File path to cropped image.
[1349] Fix | Delete
* @return int Attachment ID.
[1350] Fix | Delete
*/
[1351] Fix | Delete
final public function insert_attachment( $attachment, $cropped ) {
[1352] Fix | Delete
$parent_id = isset( $attachment['post_parent'] ) ? $attachment['post_parent'] : null;
[1353] Fix | Delete
unset( $attachment['post_parent'] );
[1354] Fix | Delete
[1355] Fix | Delete
$attachment_id = wp_insert_attachment( $attachment, $cropped );
[1356] Fix | Delete
$metadata = wp_generate_attachment_metadata( $attachment_id, $cropped );
[1357] Fix | Delete
[1358] Fix | Delete
// If this is a crop, save the original attachment ID as metadata.
[1359] Fix | Delete
if ( $parent_id ) {
[1360] Fix | Delete
$metadata['attachment_parent'] = $parent_id;
[1361] Fix | Delete
}
[1362] Fix | Delete
[1363] Fix | Delete
/**
[1364] Fix | Delete
* Filters the header image attachment metadata.
[1365] Fix | Delete
*
[1366] Fix | Delete
* @since 3.9.0
[1367] Fix | Delete
*
[1368] Fix | Delete
* @see wp_generate_attachment_metadata()
[1369] Fix | Delete
*
[1370] Fix | Delete
* @param array $metadata Attachment metadata.
[1371] Fix | Delete
*/
[1372] Fix | Delete
$metadata = apply_filters( 'wp_header_image_attachment_metadata', $metadata );
[1373] Fix | Delete
[1374] Fix | Delete
wp_update_attachment_metadata( $attachment_id, $metadata );
[1375] Fix | Delete
[1376] Fix | Delete
return $attachment_id;
[1377] Fix | Delete
}
[1378] Fix | Delete
[1379] Fix | Delete
/**
[1380] Fix | Delete
* Gets attachment uploaded by Media Manager, crops it, then saves it as a
[1381] Fix | Delete
* new object. Returns JSON-encoded object details.
[1382] Fix | Delete
*
[1383] Fix | Delete
* @since 3.9.0
[1384] Fix | Delete
*/
[1385] Fix | Delete
public function ajax_header_crop() {
[1386] Fix | Delete
check_ajax_referer( 'image_editor-' . $_POST['id'], 'nonce' );
[1387] Fix | Delete
[1388] Fix | Delete
if ( ! current_user_can( 'edit_theme_options' ) ) {
[1389] Fix | Delete
wp_send_json_error();
[1390] Fix | Delete
}
[1391] Fix | Delete
[1392] Fix | Delete
if ( ! current_theme_supports( 'custom-header', 'uploads' ) ) {
[1393] Fix | Delete
wp_send_json_error();
[1394] Fix | Delete
}
[1395] Fix | Delete
[1396] Fix | Delete
$crop_details = $_POST['cropDetails'];
[1397] Fix | Delete
[1398] Fix | Delete
$dimensions = $this->get_header_dimensions(
[1399] Fix | Delete
array(
[1400] Fix | Delete
'height' => $crop_details['height'],
[1401] Fix | Delete
'width' => $crop_details['width'],
[1402] Fix | Delete
)
[1403] Fix | Delete
);
[1404] Fix | Delete
[1405] Fix | Delete
$attachment_id = absint( $_POST['id'] );
[1406] Fix | Delete
[1407] Fix | Delete
$cropped = wp_crop_image(
[1408] Fix | Delete
$attachment_id,
[1409] Fix | Delete
(int) $crop_details['x1'],
[1410] Fix | Delete
(int) $crop_details['y1'],
[1411] Fix | Delete
(int) $crop_details['width'],
[1412] Fix | Delete
(int) $crop_details['height'],
[1413] Fix | Delete
(int) $dimensions['dst_width'],
[1414] Fix | Delete
(int) $dimensions['dst_height']
[1415] Fix | Delete
);
[1416] Fix | Delete
[1417] Fix | Delete
if ( ! $cropped || is_wp_error( $cropped ) ) {
[1418] Fix | Delete
wp_send_json_error( array( 'message' => __( 'Image could not be processed. Please go back and try again.' ) ) );
[1419] Fix | Delete
}
[1420] Fix | Delete
[1421] Fix | Delete
/** This filter is documented in wp-admin/includes/class-custom-image-header.php */
[1422] Fix | Delete
$cropped = apply_filters( 'wp_create_file_in_uploads', $cropped, $attachment_id ); // For replication.
[1423] Fix | Delete
[1424] Fix | Delete
$attachment = wp_copy_parent_attachment_properties( $cropped, $attachment_id, 'custom-header' );
[1425] Fix | Delete
[1426] Fix | Delete
$previous = $this->get_previous_crop( $attachment );
[1427] Fix | Delete
[1428] Fix | Delete
if ( $previous ) {
[1429] Fix | Delete
$attachment['ID'] = $previous;
[1430] Fix | Delete
} else {
[1431] Fix | Delete
unset( $attachment['ID'] );
[1432] Fix | Delete
}
[1433] Fix | Delete
[1434] Fix | Delete
$new_attachment_id = $this->insert_attachment( $attachment, $cropped );
[1435] Fix | Delete
[1436] Fix | Delete
$attachment['attachment_id'] = $new_attachment_id;
[1437] Fix | Delete
$attachment['url'] = wp_get_attachment_url( $new_attachment_id );
[1438] Fix | Delete
[1439] Fix | Delete
$attachment['width'] = $dimensions['dst_width'];
[1440] Fix | Delete
$attachment['height'] = $dimensions['dst_height'];
[1441] Fix | Delete
[1442] Fix | Delete
wp_send_json_success( $attachment );
[1443] Fix | Delete
}
[1444] Fix | Delete
[1445] Fix | Delete
/**
[1446] Fix | Delete
* Given an attachment ID for a header image, updates its "last used"
[1447] Fix | Delete
* timestamp to now.
[1448] Fix | Delete
*
[1449] Fix | Delete
* Triggered when the user tries adds a new header image from the
[1450] Fix | Delete
* Media Manager, even if s/he doesn't save that change.
[1451] Fix | Delete
*
[1452] Fix | Delete
* @since 3.9.0
[1453] Fix | Delete
*/
[1454] Fix | Delete
public function ajax_header_add() {
[1455] Fix | Delete
check_ajax_referer( 'header-add', 'nonce' );
[1456] Fix | Delete
[1457] Fix | Delete
if ( ! current_user_can( 'edit_theme_options' ) ) {
[1458] Fix | Delete
wp_send_json_error();
[1459] Fix | Delete
}
[1460] Fix | Delete
[1461] Fix | Delete
$attachment_id = absint( $_POST['attachment_id'] );
[1462] Fix | Delete
if ( $attachment_id < 1 ) {
[1463] Fix | Delete
wp_send_json_error();
[1464] Fix | Delete
}
[1465] Fix | Delete
[1466] Fix | Delete
$key = '_wp_attachment_custom_header_last_used_' . get_stylesheet();
[1467] Fix | Delete
update_post_meta( $attachment_id, $key, time() );
[1468] Fix | Delete
update_post_meta( $attachment_id, '_wp_attachment_is_custom_header', get_stylesheet() );
[1469] Fix | Delete
[1470] Fix | Delete
wp_send_json_success();
[1471] Fix | Delete
}
[1472] Fix | Delete
[1473] Fix | Delete
/**
[1474] Fix | Delete
* Given an attachment ID for a header image, unsets it as a user-uploaded
[1475] Fix | Delete
* header image for the active theme.
[1476] Fix | Delete
*
[1477] Fix | Delete
* Triggered when the user clicks the overlay "X" button next to each image
[1478] Fix | Delete
* choice in the Customizer's Header tool.
[1479] Fix | Delete
*
[1480] Fix | Delete
* @since 3.9.0
[1481] Fix | Delete
*/
[1482] Fix | Delete
public function ajax_header_remove() {
[1483] Fix | Delete
check_ajax_referer( 'header-remove', 'nonce' );
[1484] Fix | Delete
[1485] Fix | Delete
if ( ! current_user_can( 'edit_theme_options' ) ) {
[1486] Fix | Delete
wp_send_json_error();
[1487] Fix | Delete
}
[1488] Fix | Delete
[1489] Fix | Delete
$attachment_id = absint( $_POST['attachment_id'] );
[1490] Fix | Delete
if ( $attachment_id < 1 ) {
[1491] Fix | Delete
wp_send_json_error();
[1492] Fix | Delete
}
[1493] Fix | Delete
[1494] Fix | Delete
$key = '_wp_attachment_custom_header_last_used_' . get_stylesheet();
[1495] Fix | Delete
delete_post_meta( $attachment_id, $key );
[1496] Fix | Delete
delete_post_meta( $attachment_id, '_wp_attachment_is_custom_header', get_stylesheet() );
[1497] Fix | Delete
[1498] Fix | Delete
wp_send_json_success();
[1499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function