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.../httpdocs/clone/wp-inclu...
File: media.php
/**
[1000] Fix | Delete
* Filters the attachment image source result.
[1001] Fix | Delete
*
[1002] Fix | Delete
* @since 4.3.0
[1003] Fix | Delete
*
[1004] Fix | Delete
* @param array|false $image {
[1005] Fix | Delete
* Array of image data, or boolean false if no image is available.
[1006] Fix | Delete
*
[1007] Fix | Delete
* @type string $0 Image source URL.
[1008] Fix | Delete
* @type int $1 Image width in pixels.
[1009] Fix | Delete
* @type int $2 Image height in pixels.
[1010] Fix | Delete
* @type bool $3 Whether the image is a resized image.
[1011] Fix | Delete
* }
[1012] Fix | Delete
* @param int $attachment_id Image attachment ID.
[1013] Fix | Delete
* @param string|int[] $size Requested image size. Can be any registered image size name, or
[1014] Fix | Delete
* an array of width and height values in pixels (in that order).
[1015] Fix | Delete
* @param bool $icon Whether the image should be treated as an icon.
[1016] Fix | Delete
*/
[1017] Fix | Delete
return apply_filters( 'wp_get_attachment_image_src', $image, $attachment_id, $size, $icon );
[1018] Fix | Delete
}
[1019] Fix | Delete
[1020] Fix | Delete
/**
[1021] Fix | Delete
* Gets an HTML img element representing an image attachment.
[1022] Fix | Delete
*
[1023] Fix | Delete
* While `$size` will accept an array, it is better to register a size with
[1024] Fix | Delete
* add_image_size() so that a cropped version is generated. It's much more
[1025] Fix | Delete
* efficient than having to find the closest-sized image and then having the
[1026] Fix | Delete
* browser scale down the image.
[1027] Fix | Delete
*
[1028] Fix | Delete
* @since 2.5.0
[1029] Fix | Delete
* @since 4.4.0 The `$srcset` and `$sizes` attributes were added.
[1030] Fix | Delete
* @since 5.5.0 The `$loading` attribute was added.
[1031] Fix | Delete
* @since 6.1.0 The `$decoding` attribute was added.
[1032] Fix | Delete
*
[1033] Fix | Delete
* @param int $attachment_id Image attachment ID.
[1034] Fix | Delete
* @param string|int[] $size Optional. Image size. Accepts any registered image size name, or an array
[1035] Fix | Delete
* of width and height values in pixels (in that order). Default 'thumbnail'.
[1036] Fix | Delete
* @param bool $icon Optional. Whether the image should be treated as an icon. Default false.
[1037] Fix | Delete
* @param string|array $attr {
[1038] Fix | Delete
* Optional. Attributes for the image markup.
[1039] Fix | Delete
*
[1040] Fix | Delete
* @type string $src Image attachment URL.
[1041] Fix | Delete
* @type string $class CSS class name or space-separated list of classes.
[1042] Fix | Delete
* Default `attachment-$size_class size-$size_class`,
[1043] Fix | Delete
* where `$size_class` is the image size being requested.
[1044] Fix | Delete
* @type string $alt Image description for the alt attribute.
[1045] Fix | Delete
* @type string $srcset The 'srcset' attribute value.
[1046] Fix | Delete
* @type string $sizes The 'sizes' attribute value.
[1047] Fix | Delete
* @type string|false $loading The 'loading' attribute value. Passing a value of false
[1048] Fix | Delete
* will result in the attribute being omitted for the image.
[1049] Fix | Delete
* Default determined by {@see wp_get_loading_optimization_attributes()}.
[1050] Fix | Delete
* @type string $decoding The 'decoding' attribute value. Possible values are
[1051] Fix | Delete
* 'async' (default), 'sync', or 'auto'. Passing false or an empty
[1052] Fix | Delete
* string will result in the attribute being omitted.
[1053] Fix | Delete
* @type string $fetchpriority The 'fetchpriority' attribute value, whether `high`, `low`, or `auto`.
[1054] Fix | Delete
* Default determined by {@see wp_get_loading_optimization_attributes()}.
[1055] Fix | Delete
* }
[1056] Fix | Delete
* @return string HTML img element or empty string on failure.
[1057] Fix | Delete
*/
[1058] Fix | Delete
function wp_get_attachment_image( $attachment_id, $size = 'thumbnail', $icon = false, $attr = '' ) {
[1059] Fix | Delete
$html = '';
[1060] Fix | Delete
$image = wp_get_attachment_image_src( $attachment_id, $size, $icon );
[1061] Fix | Delete
[1062] Fix | Delete
if ( $image ) {
[1063] Fix | Delete
list( $src, $width, $height ) = $image;
[1064] Fix | Delete
[1065] Fix | Delete
$attachment = get_post( $attachment_id );
[1066] Fix | Delete
$hwstring = image_hwstring( $width, $height );
[1067] Fix | Delete
$size_class = $size;
[1068] Fix | Delete
[1069] Fix | Delete
if ( is_array( $size_class ) ) {
[1070] Fix | Delete
$size_class = implode( 'x', $size_class );
[1071] Fix | Delete
}
[1072] Fix | Delete
[1073] Fix | Delete
$default_attr = array(
[1074] Fix | Delete
'src' => $src,
[1075] Fix | Delete
'class' => "attachment-$size_class size-$size_class",
[1076] Fix | Delete
'alt' => trim( strip_tags( get_post_meta( $attachment_id, '_wp_attachment_image_alt', true ) ) ),
[1077] Fix | Delete
);
[1078] Fix | Delete
[1079] Fix | Delete
/**
[1080] Fix | Delete
* Filters the context in which wp_get_attachment_image() is used.
[1081] Fix | Delete
*
[1082] Fix | Delete
* @since 6.3.0
[1083] Fix | Delete
*
[1084] Fix | Delete
* @param string $context The context. Default 'wp_get_attachment_image'.
[1085] Fix | Delete
*/
[1086] Fix | Delete
$context = apply_filters( 'wp_get_attachment_image_context', 'wp_get_attachment_image' );
[1087] Fix | Delete
$attr = wp_parse_args( $attr, $default_attr );
[1088] Fix | Delete
[1089] Fix | Delete
$loading_attr = $attr;
[1090] Fix | Delete
$loading_attr['width'] = $width;
[1091] Fix | Delete
$loading_attr['height'] = $height;
[1092] Fix | Delete
$loading_optimization_attr = wp_get_loading_optimization_attributes(
[1093] Fix | Delete
'img',
[1094] Fix | Delete
$loading_attr,
[1095] Fix | Delete
$context
[1096] Fix | Delete
);
[1097] Fix | Delete
[1098] Fix | Delete
// Add loading optimization attributes if not available.
[1099] Fix | Delete
$attr = array_merge( $attr, $loading_optimization_attr );
[1100] Fix | Delete
[1101] Fix | Delete
// Omit the `decoding` attribute if the value is invalid according to the spec.
[1102] Fix | Delete
if ( empty( $attr['decoding'] ) || ! in_array( $attr['decoding'], array( 'async', 'sync', 'auto' ), true ) ) {
[1103] Fix | Delete
unset( $attr['decoding'] );
[1104] Fix | Delete
}
[1105] Fix | Delete
[1106] Fix | Delete
/*
[1107] Fix | Delete
* If the default value of `lazy` for the `loading` attribute is overridden
[1108] Fix | Delete
* to omit the attribute for this image, ensure it is not included.
[1109] Fix | Delete
*/
[1110] Fix | Delete
if ( isset( $attr['loading'] ) && ! $attr['loading'] ) {
[1111] Fix | Delete
unset( $attr['loading'] );
[1112] Fix | Delete
}
[1113] Fix | Delete
[1114] Fix | Delete
// If the `fetchpriority` attribute is overridden and set to false or an empty string.
[1115] Fix | Delete
if ( isset( $attr['fetchpriority'] ) && ! $attr['fetchpriority'] ) {
[1116] Fix | Delete
unset( $attr['fetchpriority'] );
[1117] Fix | Delete
}
[1118] Fix | Delete
[1119] Fix | Delete
// Generate 'srcset' and 'sizes' if not already present.
[1120] Fix | Delete
if ( empty( $attr['srcset'] ) ) {
[1121] Fix | Delete
$image_meta = wp_get_attachment_metadata( $attachment_id );
[1122] Fix | Delete
[1123] Fix | Delete
if ( is_array( $image_meta ) ) {
[1124] Fix | Delete
$size_array = array( absint( $width ), absint( $height ) );
[1125] Fix | Delete
$srcset = wp_calculate_image_srcset( $size_array, $src, $image_meta, $attachment_id );
[1126] Fix | Delete
$sizes = wp_calculate_image_sizes( $size_array, $src, $image_meta, $attachment_id );
[1127] Fix | Delete
[1128] Fix | Delete
if ( $srcset && ( $sizes || ! empty( $attr['sizes'] ) ) ) {
[1129] Fix | Delete
$attr['srcset'] = $srcset;
[1130] Fix | Delete
[1131] Fix | Delete
if ( empty( $attr['sizes'] ) ) {
[1132] Fix | Delete
$attr['sizes'] = $sizes;
[1133] Fix | Delete
}
[1134] Fix | Delete
}
[1135] Fix | Delete
}
[1136] Fix | Delete
}
[1137] Fix | Delete
[1138] Fix | Delete
/**
[1139] Fix | Delete
* Filters the list of attachment image attributes.
[1140] Fix | Delete
*
[1141] Fix | Delete
* @since 2.8.0
[1142] Fix | Delete
*
[1143] Fix | Delete
* @param string[] $attr Array of attribute values for the image markup, keyed by attribute name.
[1144] Fix | Delete
* See wp_get_attachment_image().
[1145] Fix | Delete
* @param WP_Post $attachment Image attachment post.
[1146] Fix | Delete
* @param string|int[] $size Requested image size. Can be any registered image size name, or
[1147] Fix | Delete
* an array of width and height values in pixels (in that order).
[1148] Fix | Delete
*/
[1149] Fix | Delete
$attr = apply_filters( 'wp_get_attachment_image_attributes', $attr, $attachment, $size );
[1150] Fix | Delete
[1151] Fix | Delete
$attr = array_map( 'esc_attr', $attr );
[1152] Fix | Delete
$html = rtrim( "<img $hwstring" );
[1153] Fix | Delete
[1154] Fix | Delete
foreach ( $attr as $name => $value ) {
[1155] Fix | Delete
$html .= " $name=" . '"' . $value . '"';
[1156] Fix | Delete
}
[1157] Fix | Delete
[1158] Fix | Delete
$html .= ' />';
[1159] Fix | Delete
}
[1160] Fix | Delete
[1161] Fix | Delete
/**
[1162] Fix | Delete
* Filters the HTML img element representing an image attachment.
[1163] Fix | Delete
*
[1164] Fix | Delete
* @since 5.6.0
[1165] Fix | Delete
*
[1166] Fix | Delete
* @param string $html HTML img element or empty string on failure.
[1167] Fix | Delete
* @param int $attachment_id Image attachment ID.
[1168] Fix | Delete
* @param string|int[] $size Requested image size. Can be any registered image size name, or
[1169] Fix | Delete
* an array of width and height values in pixels (in that order).
[1170] Fix | Delete
* @param bool $icon Whether the image should be treated as an icon.
[1171] Fix | Delete
* @param string[] $attr Array of attribute values for the image markup, keyed by attribute name.
[1172] Fix | Delete
* See wp_get_attachment_image().
[1173] Fix | Delete
*/
[1174] Fix | Delete
return apply_filters( 'wp_get_attachment_image', $html, $attachment_id, $size, $icon, $attr );
[1175] Fix | Delete
}
[1176] Fix | Delete
[1177] Fix | Delete
/**
[1178] Fix | Delete
* Gets the URL of an image attachment.
[1179] Fix | Delete
*
[1180] Fix | Delete
* @since 4.4.0
[1181] Fix | Delete
*
[1182] Fix | Delete
* @param int $attachment_id Image attachment ID.
[1183] Fix | Delete
* @param string|int[] $size Optional. Image size. Accepts any registered image size name, or an array of
[1184] Fix | Delete
* width and height values in pixels (in that order). Default 'thumbnail'.
[1185] Fix | Delete
* @param bool $icon Optional. Whether the image should be treated as an icon. Default false.
[1186] Fix | Delete
* @return string|false Attachment URL or false if no image is available. If `$size` does not match
[1187] Fix | Delete
* any registered image size, the original image URL will be returned.
[1188] Fix | Delete
*/
[1189] Fix | Delete
function wp_get_attachment_image_url( $attachment_id, $size = 'thumbnail', $icon = false ) {
[1190] Fix | Delete
$image = wp_get_attachment_image_src( $attachment_id, $size, $icon );
[1191] Fix | Delete
return isset( $image[0] ) ? $image[0] : false;
[1192] Fix | Delete
}
[1193] Fix | Delete
[1194] Fix | Delete
/**
[1195] Fix | Delete
* Gets the attachment path relative to the upload directory.
[1196] Fix | Delete
*
[1197] Fix | Delete
* @since 4.4.1
[1198] Fix | Delete
* @access private
[1199] Fix | Delete
*
[1200] Fix | Delete
* @param string $file Attachment file name.
[1201] Fix | Delete
* @return string Attachment path relative to the upload directory.
[1202] Fix | Delete
*/
[1203] Fix | Delete
function _wp_get_attachment_relative_path( $file ) {
[1204] Fix | Delete
$dirname = dirname( $file );
[1205] Fix | Delete
[1206] Fix | Delete
if ( '.' === $dirname ) {
[1207] Fix | Delete
return '';
[1208] Fix | Delete
}
[1209] Fix | Delete
[1210] Fix | Delete
if ( str_contains( $dirname, 'wp-content/uploads' ) ) {
[1211] Fix | Delete
// Get the directory name relative to the upload directory (back compat for pre-2.7 uploads).
[1212] Fix | Delete
$dirname = substr( $dirname, strpos( $dirname, 'wp-content/uploads' ) + 18 );
[1213] Fix | Delete
$dirname = ltrim( $dirname, '/' );
[1214] Fix | Delete
}
[1215] Fix | Delete
[1216] Fix | Delete
return $dirname;
[1217] Fix | Delete
}
[1218] Fix | Delete
[1219] Fix | Delete
/**
[1220] Fix | Delete
* Gets the image size as array from its meta data.
[1221] Fix | Delete
*
[1222] Fix | Delete
* Used for responsive images.
[1223] Fix | Delete
*
[1224] Fix | Delete
* @since 4.4.0
[1225] Fix | Delete
* @access private
[1226] Fix | Delete
*
[1227] Fix | Delete
* @param string $size_name Image size. Accepts any registered image size name.
[1228] Fix | Delete
* @param array $image_meta The image meta data.
[1229] Fix | Delete
* @return array|false {
[1230] Fix | Delete
* Array of width and height or false if the size isn't present in the meta data.
[1231] Fix | Delete
*
[1232] Fix | Delete
* @type int $0 Image width.
[1233] Fix | Delete
* @type int $1 Image height.
[1234] Fix | Delete
* }
[1235] Fix | Delete
*/
[1236] Fix | Delete
function _wp_get_image_size_from_meta( $size_name, $image_meta ) {
[1237] Fix | Delete
if ( 'full' === $size_name ) {
[1238] Fix | Delete
return array(
[1239] Fix | Delete
absint( $image_meta['width'] ),
[1240] Fix | Delete
absint( $image_meta['height'] ),
[1241] Fix | Delete
);
[1242] Fix | Delete
} elseif ( ! empty( $image_meta['sizes'][ $size_name ] ) ) {
[1243] Fix | Delete
return array(
[1244] Fix | Delete
absint( $image_meta['sizes'][ $size_name ]['width'] ),
[1245] Fix | Delete
absint( $image_meta['sizes'][ $size_name ]['height'] ),
[1246] Fix | Delete
);
[1247] Fix | Delete
}
[1248] Fix | Delete
[1249] Fix | Delete
return false;
[1250] Fix | Delete
}
[1251] Fix | Delete
[1252] Fix | Delete
/**
[1253] Fix | Delete
* Retrieves the value for an image attachment's 'srcset' attribute.
[1254] Fix | Delete
*
[1255] Fix | Delete
* @since 4.4.0
[1256] Fix | Delete
*
[1257] Fix | Delete
* @see wp_calculate_image_srcset()
[1258] Fix | Delete
*
[1259] Fix | Delete
* @param int $attachment_id Image attachment ID.
[1260] Fix | Delete
* @param string|int[] $size Optional. Image size. Accepts any registered image size name, or an array of
[1261] Fix | Delete
* width and height values in pixels (in that order). Default 'medium'.
[1262] Fix | Delete
* @param array|null $image_meta Optional. The image meta data as returned by 'wp_get_attachment_metadata()'.
[1263] Fix | Delete
* Default null.
[1264] Fix | Delete
* @return string|false A 'srcset' value string or false.
[1265] Fix | Delete
*/
[1266] Fix | Delete
function wp_get_attachment_image_srcset( $attachment_id, $size = 'medium', $image_meta = null ) {
[1267] Fix | Delete
$image = wp_get_attachment_image_src( $attachment_id, $size );
[1268] Fix | Delete
[1269] Fix | Delete
if ( ! $image ) {
[1270] Fix | Delete
return false;
[1271] Fix | Delete
}
[1272] Fix | Delete
[1273] Fix | Delete
if ( ! is_array( $image_meta ) ) {
[1274] Fix | Delete
$image_meta = wp_get_attachment_metadata( $attachment_id );
[1275] Fix | Delete
}
[1276] Fix | Delete
[1277] Fix | Delete
$image_src = $image[0];
[1278] Fix | Delete
$size_array = array(
[1279] Fix | Delete
absint( $image[1] ),
[1280] Fix | Delete
absint( $image[2] ),
[1281] Fix | Delete
);
[1282] Fix | Delete
[1283] Fix | Delete
return wp_calculate_image_srcset( $size_array, $image_src, $image_meta, $attachment_id );
[1284] Fix | Delete
}
[1285] Fix | Delete
[1286] Fix | Delete
/**
[1287] Fix | Delete
* A helper function to calculate the image sources to include in a 'srcset' attribute.
[1288] Fix | Delete
*
[1289] Fix | Delete
* @since 4.4.0
[1290] Fix | Delete
*
[1291] Fix | Delete
* @param int[] $size_array {
[1292] Fix | Delete
* An array of width and height values.
[1293] Fix | Delete
*
[1294] Fix | Delete
* @type int $0 The width in pixels.
[1295] Fix | Delete
* @type int $1 The height in pixels.
[1296] Fix | Delete
* }
[1297] Fix | Delete
* @param string $image_src The 'src' of the image.
[1298] Fix | Delete
* @param array $image_meta The image meta data as returned by 'wp_get_attachment_metadata()'.
[1299] Fix | Delete
* @param int $attachment_id Optional. The image attachment ID. Default 0.
[1300] Fix | Delete
* @return string|false The 'srcset' attribute value. False on error or when only one source exists.
[1301] Fix | Delete
*/
[1302] Fix | Delete
function wp_calculate_image_srcset( $size_array, $image_src, $image_meta, $attachment_id = 0 ) {
[1303] Fix | Delete
/**
[1304] Fix | Delete
* Pre-filters the image meta to be able to fix inconsistencies in the stored data.
[1305] Fix | Delete
*
[1306] Fix | Delete
* @since 4.5.0
[1307] Fix | Delete
*
[1308] Fix | Delete
* @param array $image_meta The image meta data as returned by 'wp_get_attachment_metadata()'.
[1309] Fix | Delete
* @param int[] $size_array {
[1310] Fix | Delete
* An array of requested width and height values.
[1311] Fix | Delete
*
[1312] Fix | Delete
* @type int $0 The width in pixels.
[1313] Fix | Delete
* @type int $1 The height in pixels.
[1314] Fix | Delete
* }
[1315] Fix | Delete
* @param string $image_src The 'src' of the image.
[1316] Fix | Delete
* @param int $attachment_id The image attachment ID or 0 if not supplied.
[1317] Fix | Delete
*/
[1318] Fix | Delete
$image_meta = apply_filters( 'wp_calculate_image_srcset_meta', $image_meta, $size_array, $image_src, $attachment_id );
[1319] Fix | Delete
[1320] Fix | Delete
if ( empty( $image_meta['sizes'] ) || ! isset( $image_meta['file'] ) || strlen( $image_meta['file'] ) < 4 ) {
[1321] Fix | Delete
return false;
[1322] Fix | Delete
}
[1323] Fix | Delete
[1324] Fix | Delete
$image_sizes = $image_meta['sizes'];
[1325] Fix | Delete
[1326] Fix | Delete
// Get the width and height of the image.
[1327] Fix | Delete
$image_width = (int) $size_array[0];
[1328] Fix | Delete
$image_height = (int) $size_array[1];
[1329] Fix | Delete
[1330] Fix | Delete
// Bail early if error/no width.
[1331] Fix | Delete
if ( $image_width < 1 ) {
[1332] Fix | Delete
return false;
[1333] Fix | Delete
}
[1334] Fix | Delete
[1335] Fix | Delete
$image_basename = wp_basename( $image_meta['file'] );
[1336] Fix | Delete
[1337] Fix | Delete
/*
[1338] Fix | Delete
* WordPress flattens animated GIFs into one frame when generating intermediate sizes.
[1339] Fix | Delete
* To avoid hiding animation in user content, if src is a full size GIF, a srcset attribute is not generated.
[1340] Fix | Delete
* If src is an intermediate size GIF, the full size is excluded from srcset to keep a flattened GIF from becoming animated.
[1341] Fix | Delete
*/
[1342] Fix | Delete
if ( ! isset( $image_sizes['thumbnail']['mime-type'] ) || 'image/gif' !== $image_sizes['thumbnail']['mime-type'] ) {
[1343] Fix | Delete
$image_sizes[] = array(
[1344] Fix | Delete
'width' => $image_meta['width'],
[1345] Fix | Delete
'height' => $image_meta['height'],
[1346] Fix | Delete
'file' => $image_basename,
[1347] Fix | Delete
);
[1348] Fix | Delete
} elseif ( str_contains( $image_src, $image_meta['file'] ) ) {
[1349] Fix | Delete
return false;
[1350] Fix | Delete
}
[1351] Fix | Delete
[1352] Fix | Delete
// Retrieve the uploads sub-directory from the full size image.
[1353] Fix | Delete
$dirname = _wp_get_attachment_relative_path( $image_meta['file'] );
[1354] Fix | Delete
[1355] Fix | Delete
if ( $dirname ) {
[1356] Fix | Delete
$dirname = trailingslashit( $dirname );
[1357] Fix | Delete
}
[1358] Fix | Delete
[1359] Fix | Delete
$upload_dir = wp_get_upload_dir();
[1360] Fix | Delete
$image_baseurl = trailingslashit( $upload_dir['baseurl'] ) . $dirname;
[1361] Fix | Delete
[1362] Fix | Delete
/*
[1363] Fix | Delete
* If currently on HTTPS, prefer HTTPS URLs when we know they're supported by the domain
[1364] Fix | Delete
* (which is to say, when they share the domain name of the current request).
[1365] Fix | Delete
*/
[1366] Fix | Delete
if ( is_ssl() && ! str_starts_with( $image_baseurl, 'https' ) ) {
[1367] Fix | Delete
/*
[1368] Fix | Delete
* Since the `Host:` header might contain a port, it should
[1369] Fix | Delete
* be compared against the image URL using the same port.
[1370] Fix | Delete
*/
[1371] Fix | Delete
$parsed = parse_url( $image_baseurl );
[1372] Fix | Delete
$domain = isset( $parsed['host'] ) ? $parsed['host'] : '';
[1373] Fix | Delete
[1374] Fix | Delete
if ( isset( $parsed['port'] ) ) {
[1375] Fix | Delete
$domain .= ':' . $parsed['port'];
[1376] Fix | Delete
}
[1377] Fix | Delete
[1378] Fix | Delete
if ( $_SERVER['HTTP_HOST'] === $domain ) {
[1379] Fix | Delete
$image_baseurl = set_url_scheme( $image_baseurl, 'https' );
[1380] Fix | Delete
}
[1381] Fix | Delete
}
[1382] Fix | Delete
[1383] Fix | Delete
/*
[1384] Fix | Delete
* Images that have been edited in WordPress after being uploaded will
[1385] Fix | Delete
* contain a unique hash. Look for that hash and use it later to filter
[1386] Fix | Delete
* out images that are leftovers from previous versions.
[1387] Fix | Delete
*/
[1388] Fix | Delete
$image_edited = preg_match( '/-e[0-9]{13}/', wp_basename( $image_src ), $image_edit_hash );
[1389] Fix | Delete
[1390] Fix | Delete
/**
[1391] Fix | Delete
* Filters the maximum image width to be included in a 'srcset' attribute.
[1392] Fix | Delete
*
[1393] Fix | Delete
* @since 4.4.0
[1394] Fix | Delete
*
[1395] Fix | Delete
* @param int $max_width The maximum image width to be included in the 'srcset'. Default '2048'.
[1396] Fix | Delete
* @param int[] $size_array {
[1397] Fix | Delete
* An array of requested width and height values.
[1398] Fix | Delete
*
[1399] Fix | Delete
* @type int $0 The width in pixels.
[1400] Fix | Delete
* @type int $1 The height in pixels.
[1401] Fix | Delete
* }
[1402] Fix | Delete
*/
[1403] Fix | Delete
$max_srcset_image_width = apply_filters( 'max_srcset_image_width', 2048, $size_array );
[1404] Fix | Delete
[1405] Fix | Delete
// Array to hold URL candidates.
[1406] Fix | Delete
$sources = array();
[1407] Fix | Delete
[1408] Fix | Delete
/**
[1409] Fix | Delete
* To make sure the ID matches our image src, we will check to see if any sizes in our attachment
[1410] Fix | Delete
* meta match our $image_src. If no matches are found we don't return a srcset to avoid serving
[1411] Fix | Delete
* an incorrect image. See #35045.
[1412] Fix | Delete
*/
[1413] Fix | Delete
$src_matched = false;
[1414] Fix | Delete
[1415] Fix | Delete
/*
[1416] Fix | Delete
* Loop through available images. Only use images that are resized
[1417] Fix | Delete
* versions of the same edit.
[1418] Fix | Delete
*/
[1419] Fix | Delete
foreach ( $image_sizes as $image ) {
[1420] Fix | Delete
$is_src = false;
[1421] Fix | Delete
[1422] Fix | Delete
// Check if image meta isn't corrupted.
[1423] Fix | Delete
if ( ! is_array( $image ) ) {
[1424] Fix | Delete
continue;
[1425] Fix | Delete
}
[1426] Fix | Delete
[1427] Fix | Delete
// If the file name is part of the `src`, we've confirmed a match.
[1428] Fix | Delete
if ( ! $src_matched && str_contains( $image_src, $dirname . $image['file'] ) ) {
[1429] Fix | Delete
$src_matched = true;
[1430] Fix | Delete
$is_src = true;
[1431] Fix | Delete
}
[1432] Fix | Delete
[1433] Fix | Delete
// Filter out images that are from previous edits.
[1434] Fix | Delete
if ( $image_edited && ! strpos( $image['file'], $image_edit_hash[0] ) ) {
[1435] Fix | Delete
continue;
[1436] Fix | Delete
}
[1437] Fix | Delete
[1438] Fix | Delete
/*
[1439] Fix | Delete
* Filters out images that are wider than '$max_srcset_image_width' unless
[1440] Fix | Delete
* that file is in the 'src' attribute.
[1441] Fix | Delete
*/
[1442] Fix | Delete
if ( $max_srcset_image_width && $image['width'] > $max_srcset_image_width && ! $is_src ) {
[1443] Fix | Delete
continue;
[1444] Fix | Delete
}
[1445] Fix | Delete
[1446] Fix | Delete
// If the image dimensions are within 1px of the expected size, use it.
[1447] Fix | Delete
if ( wp_image_matches_ratio( $image_width, $image_height, $image['width'], $image['height'] ) ) {
[1448] Fix | Delete
// Add the URL, descriptor, and value to the sources array to be returned.
[1449] Fix | Delete
$source = array(
[1450] Fix | Delete
'url' => $image_baseurl . $image['file'],
[1451] Fix | Delete
'descriptor' => 'w',
[1452] Fix | Delete
'value' => $image['width'],
[1453] Fix | Delete
);
[1454] Fix | Delete
[1455] Fix | Delete
// The 'src' image has to be the first in the 'srcset', because of a bug in iOS8. See #35030.
[1456] Fix | Delete
if ( $is_src ) {
[1457] Fix | Delete
$sources = array( $image['width'] => $source ) + $sources;
[1458] Fix | Delete
} else {
[1459] Fix | Delete
$sources[ $image['width'] ] = $source;
[1460] Fix | Delete
}
[1461] Fix | Delete
}
[1462] Fix | Delete
}
[1463] Fix | Delete
[1464] Fix | Delete
/**
[1465] Fix | Delete
* Filters an image's 'srcset' sources.
[1466] Fix | Delete
*
[1467] Fix | Delete
* @since 4.4.0
[1468] Fix | Delete
*
[1469] Fix | Delete
* @param array $sources {
[1470] Fix | Delete
* One or more arrays of source data to include in the 'srcset'.
[1471] Fix | Delete
*
[1472] Fix | Delete
* @type array $width {
[1473] Fix | Delete
* @type string $url The URL of an image source.
[1474] Fix | Delete
* @type string $descriptor The descriptor type used in the image candidate string,
[1475] Fix | Delete
* either 'w' or 'x'.
[1476] Fix | Delete
* @type int $value The source width if paired with a 'w' descriptor, or a
[1477] Fix | Delete
* pixel density value if paired with an 'x' descriptor.
[1478] Fix | Delete
* }
[1479] Fix | Delete
* }
[1480] Fix | Delete
* @param array $size_array {
[1481] Fix | Delete
* An array of requested width and height values.
[1482] Fix | Delete
*
[1483] Fix | Delete
* @type int $0 The width in pixels.
[1484] Fix | Delete
* @type int $1 The height in pixels.
[1485] Fix | Delete
* }
[1486] Fix | Delete
* @param string $image_src The 'src' of the image.
[1487] Fix | Delete
* @param array $image_meta The image meta data as returned by 'wp_get_attachment_metadata()'.
[1488] Fix | Delete
* @param int $attachment_id Image attachment ID or 0.
[1489] Fix | Delete
*/
[1490] Fix | Delete
$sources = apply_filters( 'wp_calculate_image_srcset', $sources, $size_array, $image_src, $image_meta, $attachment_id );
[1491] Fix | Delete
[1492] Fix | Delete
// Only return a 'srcset' value if there is more than one source.
[1493] Fix | Delete
if ( ! $src_matched || ! is_array( $sources ) || count( $sources ) < 2 ) {
[1494] Fix | Delete
return false;
[1495] Fix | Delete
}
[1496] Fix | Delete
[1497] Fix | Delete
$srcset = '';
[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