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
*
[500] Fix | Delete
* @param int[] $dimensions {
[501] Fix | Delete
* An array of width and height values.
[502] Fix | Delete
*
[503] Fix | Delete
* @type int $0 The width in pixels.
[504] Fix | Delete
* @type int $1 The height in pixels.
[505] Fix | Delete
* }
[506] Fix | Delete
* @param int $current_width The current width of the image.
[507] Fix | Delete
* @param int $current_height The current height of the image.
[508] Fix | Delete
* @param int $max_width The maximum width permitted.
[509] Fix | Delete
* @param int $max_height The maximum height permitted.
[510] Fix | Delete
*/
[511] Fix | Delete
return apply_filters( 'wp_constrain_dimensions', array( $w, $h ), $current_width, $current_height, $max_width, $max_height );
[512] Fix | Delete
}
[513] Fix | Delete
[514] Fix | Delete
/**
[515] Fix | Delete
* Retrieves calculated resize dimensions for use in WP_Image_Editor.
[516] Fix | Delete
*
[517] Fix | Delete
* Calculates dimensions and coordinates for a resized image that fits
[518] Fix | Delete
* within a specified width and height.
[519] Fix | Delete
*
[520] Fix | Delete
* @since 2.5.0
[521] Fix | Delete
*
[522] Fix | Delete
* @param int $orig_w Original width in pixels.
[523] Fix | Delete
* @param int $orig_h Original height in pixels.
[524] Fix | Delete
* @param int $dest_w New width in pixels.
[525] Fix | Delete
* @param int $dest_h New height in pixels.
[526] Fix | Delete
* @param bool|array $crop {
[527] Fix | Delete
* Optional. Image cropping behavior. If false, the image will be scaled (default).
[528] Fix | Delete
* If true, image will be cropped to the specified dimensions using center positions.
[529] Fix | Delete
* If an array, the image will be cropped using the array to specify the crop location:
[530] Fix | Delete
*
[531] Fix | Delete
* @type string $0 The x crop position. Accepts 'left' 'center', or 'right'.
[532] Fix | Delete
* @type string $1 The y crop position. Accepts 'top', 'center', or 'bottom'.
[533] Fix | Delete
* }
[534] Fix | Delete
* @return array|false Returned array matches parameters for `imagecopyresampled()`. False on failure.
[535] Fix | Delete
*/
[536] Fix | Delete
function image_resize_dimensions( $orig_w, $orig_h, $dest_w, $dest_h, $crop = false ) {
[537] Fix | Delete
[538] Fix | Delete
if ( $orig_w <= 0 || $orig_h <= 0 ) {
[539] Fix | Delete
return false;
[540] Fix | Delete
}
[541] Fix | Delete
// At least one of $dest_w or $dest_h must be specific.
[542] Fix | Delete
if ( $dest_w <= 0 && $dest_h <= 0 ) {
[543] Fix | Delete
return false;
[544] Fix | Delete
}
[545] Fix | Delete
[546] Fix | Delete
/**
[547] Fix | Delete
* Filters whether to preempt calculating the image resize dimensions.
[548] Fix | Delete
*
[549] Fix | Delete
* Returning a non-null value from the filter will effectively short-circuit
[550] Fix | Delete
* image_resize_dimensions(), returning that value instead.
[551] Fix | Delete
*
[552] Fix | Delete
* @since 3.4.0
[553] Fix | Delete
*
[554] Fix | Delete
* @param null|mixed $null Whether to preempt output of the resize dimensions.
[555] Fix | Delete
* @param int $orig_w Original width in pixels.
[556] Fix | Delete
* @param int $orig_h Original height in pixels.
[557] Fix | Delete
* @param int $dest_w New width in pixels.
[558] Fix | Delete
* @param int $dest_h New height in pixels.
[559] Fix | Delete
* @param bool|array $crop Whether to crop image to specified width and height or resize.
[560] Fix | Delete
* An array can specify positioning of the crop area. Default false.
[561] Fix | Delete
*/
[562] Fix | Delete
$output = apply_filters( 'image_resize_dimensions', null, $orig_w, $orig_h, $dest_w, $dest_h, $crop );
[563] Fix | Delete
[564] Fix | Delete
if ( null !== $output ) {
[565] Fix | Delete
return $output;
[566] Fix | Delete
}
[567] Fix | Delete
[568] Fix | Delete
// Stop if the destination size is larger than the original image dimensions.
[569] Fix | Delete
if ( empty( $dest_h ) ) {
[570] Fix | Delete
if ( $orig_w < $dest_w ) {
[571] Fix | Delete
return false;
[572] Fix | Delete
}
[573] Fix | Delete
} elseif ( empty( $dest_w ) ) {
[574] Fix | Delete
if ( $orig_h < $dest_h ) {
[575] Fix | Delete
return false;
[576] Fix | Delete
}
[577] Fix | Delete
} else {
[578] Fix | Delete
if ( $orig_w < $dest_w && $orig_h < $dest_h ) {
[579] Fix | Delete
return false;
[580] Fix | Delete
}
[581] Fix | Delete
}
[582] Fix | Delete
[583] Fix | Delete
if ( $crop ) {
[584] Fix | Delete
/*
[585] Fix | Delete
* Crop the largest possible portion of the original image that we can size to $dest_w x $dest_h.
[586] Fix | Delete
* Note that the requested crop dimensions are used as a maximum bounding box for the original image.
[587] Fix | Delete
* If the original image's width or height is less than the requested width or height
[588] Fix | Delete
* only the greater one will be cropped.
[589] Fix | Delete
* For example when the original image is 600x300, and the requested crop dimensions are 400x400,
[590] Fix | Delete
* the resulting image will be 400x300.
[591] Fix | Delete
*/
[592] Fix | Delete
$aspect_ratio = $orig_w / $orig_h;
[593] Fix | Delete
$new_w = min( $dest_w, $orig_w );
[594] Fix | Delete
$new_h = min( $dest_h, $orig_h );
[595] Fix | Delete
[596] Fix | Delete
if ( ! $new_w ) {
[597] Fix | Delete
$new_w = (int) round( $new_h * $aspect_ratio );
[598] Fix | Delete
}
[599] Fix | Delete
[600] Fix | Delete
if ( ! $new_h ) {
[601] Fix | Delete
$new_h = (int) round( $new_w / $aspect_ratio );
[602] Fix | Delete
}
[603] Fix | Delete
[604] Fix | Delete
$size_ratio = max( $new_w / $orig_w, $new_h / $orig_h );
[605] Fix | Delete
[606] Fix | Delete
$crop_w = round( $new_w / $size_ratio );
[607] Fix | Delete
$crop_h = round( $new_h / $size_ratio );
[608] Fix | Delete
[609] Fix | Delete
if ( ! is_array( $crop ) || count( $crop ) !== 2 ) {
[610] Fix | Delete
$crop = array( 'center', 'center' );
[611] Fix | Delete
}
[612] Fix | Delete
[613] Fix | Delete
list( $x, $y ) = $crop;
[614] Fix | Delete
[615] Fix | Delete
if ( 'left' === $x ) {
[616] Fix | Delete
$s_x = 0;
[617] Fix | Delete
} elseif ( 'right' === $x ) {
[618] Fix | Delete
$s_x = $orig_w - $crop_w;
[619] Fix | Delete
} else {
[620] Fix | Delete
$s_x = floor( ( $orig_w - $crop_w ) / 2 );
[621] Fix | Delete
}
[622] Fix | Delete
[623] Fix | Delete
if ( 'top' === $y ) {
[624] Fix | Delete
$s_y = 0;
[625] Fix | Delete
} elseif ( 'bottom' === $y ) {
[626] Fix | Delete
$s_y = $orig_h - $crop_h;
[627] Fix | Delete
} else {
[628] Fix | Delete
$s_y = floor( ( $orig_h - $crop_h ) / 2 );
[629] Fix | Delete
}
[630] Fix | Delete
} else {
[631] Fix | Delete
// Resize using $dest_w x $dest_h as a maximum bounding box.
[632] Fix | Delete
$crop_w = $orig_w;
[633] Fix | Delete
$crop_h = $orig_h;
[634] Fix | Delete
[635] Fix | Delete
$s_x = 0;
[636] Fix | Delete
$s_y = 0;
[637] Fix | Delete
[638] Fix | Delete
list( $new_w, $new_h ) = wp_constrain_dimensions( $orig_w, $orig_h, $dest_w, $dest_h );
[639] Fix | Delete
}
[640] Fix | Delete
[641] Fix | Delete
if ( wp_fuzzy_number_match( $new_w, $orig_w ) && wp_fuzzy_number_match( $new_h, $orig_h ) ) {
[642] Fix | Delete
// The new size has virtually the same dimensions as the original image.
[643] Fix | Delete
[644] Fix | Delete
/**
[645] Fix | Delete
* Filters whether to proceed with making an image sub-size with identical dimensions
[646] Fix | Delete
* with the original/source image. Differences of 1px may be due to rounding and are ignored.
[647] Fix | Delete
*
[648] Fix | Delete
* @since 5.3.0
[649] Fix | Delete
*
[650] Fix | Delete
* @param bool $proceed The filtered value.
[651] Fix | Delete
* @param int $orig_w Original image width.
[652] Fix | Delete
* @param int $orig_h Original image height.
[653] Fix | Delete
*/
[654] Fix | Delete
$proceed = (bool) apply_filters( 'wp_image_resize_identical_dimensions', false, $orig_w, $orig_h );
[655] Fix | Delete
[656] Fix | Delete
if ( ! $proceed ) {
[657] Fix | Delete
return false;
[658] Fix | Delete
}
[659] Fix | Delete
}
[660] Fix | Delete
[661] Fix | Delete
/*
[662] Fix | Delete
* The return array matches the parameters to imagecopyresampled().
[663] Fix | Delete
* int dst_x, int dst_y, int src_x, int src_y, int dst_w, int dst_h, int src_w, int src_h
[664] Fix | Delete
*/
[665] Fix | Delete
return array( 0, 0, (int) $s_x, (int) $s_y, (int) $new_w, (int) $new_h, (int) $crop_w, (int) $crop_h );
[666] Fix | Delete
}
[667] Fix | Delete
[668] Fix | Delete
/**
[669] Fix | Delete
* Resizes an image to make a thumbnail or intermediate size.
[670] Fix | Delete
*
[671] Fix | Delete
* The returned array has the file size, the image width, and image height. The
[672] Fix | Delete
* {@see 'image_make_intermediate_size'} filter can be used to hook in and change the
[673] Fix | Delete
* values of the returned array. The only parameter is the resized file path.
[674] Fix | Delete
*
[675] Fix | Delete
* @since 2.5.0
[676] Fix | Delete
*
[677] Fix | Delete
* @param string $file File path.
[678] Fix | Delete
* @param int $width Image width.
[679] Fix | Delete
* @param int $height Image height.
[680] Fix | Delete
* @param bool|array $crop {
[681] Fix | Delete
* Optional. Image cropping behavior. If false, the image will be scaled (default).
[682] Fix | Delete
* If true, image will be cropped to the specified dimensions using center positions.
[683] Fix | Delete
* If an array, the image will be cropped using the array to specify the crop location:
[684] Fix | Delete
*
[685] Fix | Delete
* @type string $0 The x crop position. Accepts 'left' 'center', or 'right'.
[686] Fix | Delete
* @type string $1 The y crop position. Accepts 'top', 'center', or 'bottom'.
[687] Fix | Delete
* }
[688] Fix | Delete
* @return array|false Metadata array on success. False if no image was created.
[689] Fix | Delete
*/
[690] Fix | Delete
function image_make_intermediate_size( $file, $width, $height, $crop = false ) {
[691] Fix | Delete
if ( $width || $height ) {
[692] Fix | Delete
$editor = wp_get_image_editor( $file );
[693] Fix | Delete
[694] Fix | Delete
if ( is_wp_error( $editor ) || is_wp_error( $editor->resize( $width, $height, $crop ) ) ) {
[695] Fix | Delete
return false;
[696] Fix | Delete
}
[697] Fix | Delete
[698] Fix | Delete
$resized_file = $editor->save();
[699] Fix | Delete
[700] Fix | Delete
if ( ! is_wp_error( $resized_file ) && $resized_file ) {
[701] Fix | Delete
unset( $resized_file['path'] );
[702] Fix | Delete
return $resized_file;
[703] Fix | Delete
}
[704] Fix | Delete
}
[705] Fix | Delete
return false;
[706] Fix | Delete
}
[707] Fix | Delete
[708] Fix | Delete
/**
[709] Fix | Delete
* Helper function to test if aspect ratios for two images match.
[710] Fix | Delete
*
[711] Fix | Delete
* @since 4.6.0
[712] Fix | Delete
*
[713] Fix | Delete
* @param int $source_width Width of the first image in pixels.
[714] Fix | Delete
* @param int $source_height Height of the first image in pixels.
[715] Fix | Delete
* @param int $target_width Width of the second image in pixels.
[716] Fix | Delete
* @param int $target_height Height of the second image in pixels.
[717] Fix | Delete
* @return bool True if aspect ratios match within 1px. False if not.
[718] Fix | Delete
*/
[719] Fix | Delete
function wp_image_matches_ratio( $source_width, $source_height, $target_width, $target_height ) {
[720] Fix | Delete
/*
[721] Fix | Delete
* To test for varying crops, we constrain the dimensions of the larger image
[722] Fix | Delete
* to the dimensions of the smaller image and see if they match.
[723] Fix | Delete
*/
[724] Fix | Delete
if ( $source_width > $target_width ) {
[725] Fix | Delete
$constrained_size = wp_constrain_dimensions( $source_width, $source_height, $target_width );
[726] Fix | Delete
$expected_size = array( $target_width, $target_height );
[727] Fix | Delete
} else {
[728] Fix | Delete
$constrained_size = wp_constrain_dimensions( $target_width, $target_height, $source_width );
[729] Fix | Delete
$expected_size = array( $source_width, $source_height );
[730] Fix | Delete
}
[731] Fix | Delete
[732] Fix | Delete
// If the image dimensions are within 1px of the expected size, we consider it a match.
[733] Fix | Delete
$matched = ( wp_fuzzy_number_match( $constrained_size[0], $expected_size[0] ) && wp_fuzzy_number_match( $constrained_size[1], $expected_size[1] ) );
[734] Fix | Delete
[735] Fix | Delete
return $matched;
[736] Fix | Delete
}
[737] Fix | Delete
[738] Fix | Delete
/**
[739] Fix | Delete
* Retrieves the image's intermediate size (resized) path, width, and height.
[740] Fix | Delete
*
[741] Fix | Delete
* The $size parameter can be an array with the width and height respectively.
[742] Fix | Delete
* If the size matches the 'sizes' metadata array for width and height, then it
[743] Fix | Delete
* will be used. If there is no direct match, then the nearest image size larger
[744] Fix | Delete
* than the specified size will be used. If nothing is found, then the function
[745] Fix | Delete
* will break out and return false.
[746] Fix | Delete
*
[747] Fix | Delete
* The metadata 'sizes' is used for compatible sizes that can be used for the
[748] Fix | Delete
* parameter $size value.
[749] Fix | Delete
*
[750] Fix | Delete
* The url path will be given, when the $size parameter is a string.
[751] Fix | Delete
*
[752] Fix | Delete
* If you are passing an array for the $size, you should consider using
[753] Fix | Delete
* add_image_size() so that a cropped version is generated. It's much more
[754] Fix | Delete
* efficient than having to find the closest-sized image and then having the
[755] Fix | Delete
* browser scale down the image.
[756] Fix | Delete
*
[757] Fix | Delete
* @since 2.5.0
[758] Fix | Delete
*
[759] Fix | Delete
* @param int $post_id Attachment ID.
[760] Fix | Delete
* @param string|int[] $size Optional. Image size. Accepts any registered image size name, or an array
[761] Fix | Delete
* of width and height values in pixels (in that order). Default 'thumbnail'.
[762] Fix | Delete
* @return array|false {
[763] Fix | Delete
* Array of file relative path, width, and height on success. Additionally includes absolute
[764] Fix | Delete
* path and URL if registered size is passed to `$size` parameter. False on failure.
[765] Fix | Delete
*
[766] Fix | Delete
* @type string $file Filename of image.
[767] Fix | Delete
* @type int $width Width of image in pixels.
[768] Fix | Delete
* @type int $height Height of image in pixels.
[769] Fix | Delete
* @type string $path Path of image relative to uploads directory.
[770] Fix | Delete
* @type string $url URL of image.
[771] Fix | Delete
* }
[772] Fix | Delete
*/
[773] Fix | Delete
function image_get_intermediate_size( $post_id, $size = 'thumbnail' ) {
[774] Fix | Delete
$imagedata = wp_get_attachment_metadata( $post_id );
[775] Fix | Delete
[776] Fix | Delete
if ( ! $size || ! is_array( $imagedata ) || empty( $imagedata['sizes'] ) ) {
[777] Fix | Delete
return false;
[778] Fix | Delete
}
[779] Fix | Delete
[780] Fix | Delete
$data = array();
[781] Fix | Delete
[782] Fix | Delete
// Find the best match when '$size' is an array.
[783] Fix | Delete
if ( is_array( $size ) ) {
[784] Fix | Delete
$candidates = array();
[785] Fix | Delete
[786] Fix | Delete
if ( ! isset( $imagedata['file'] ) && isset( $imagedata['sizes']['full'] ) ) {
[787] Fix | Delete
$imagedata['height'] = $imagedata['sizes']['full']['height'];
[788] Fix | Delete
$imagedata['width'] = $imagedata['sizes']['full']['width'];
[789] Fix | Delete
}
[790] Fix | Delete
[791] Fix | Delete
foreach ( $imagedata['sizes'] as $_size => $data ) {
[792] Fix | Delete
// If there's an exact match to an existing image size, short circuit.
[793] Fix | Delete
if ( (int) $data['width'] === (int) $size[0] && (int) $data['height'] === (int) $size[1] ) {
[794] Fix | Delete
$candidates[ $data['width'] * $data['height'] ] = $data;
[795] Fix | Delete
break;
[796] Fix | Delete
}
[797] Fix | Delete
[798] Fix | Delete
// If it's not an exact match, consider larger sizes with the same aspect ratio.
[799] Fix | Delete
if ( $data['width'] >= $size[0] && $data['height'] >= $size[1] ) {
[800] Fix | Delete
// If '0' is passed to either size, we test ratios against the original file.
[801] Fix | Delete
if ( 0 === $size[0] || 0 === $size[1] ) {
[802] Fix | Delete
$same_ratio = wp_image_matches_ratio( $data['width'], $data['height'], $imagedata['width'], $imagedata['height'] );
[803] Fix | Delete
} else {
[804] Fix | Delete
$same_ratio = wp_image_matches_ratio( $data['width'], $data['height'], $size[0], $size[1] );
[805] Fix | Delete
}
[806] Fix | Delete
[807] Fix | Delete
if ( $same_ratio ) {
[808] Fix | Delete
$candidates[ $data['width'] * $data['height'] ] = $data;
[809] Fix | Delete
}
[810] Fix | Delete
}
[811] Fix | Delete
}
[812] Fix | Delete
[813] Fix | Delete
if ( ! empty( $candidates ) ) {
[814] Fix | Delete
// Sort the array by size if we have more than one candidate.
[815] Fix | Delete
if ( 1 < count( $candidates ) ) {
[816] Fix | Delete
ksort( $candidates );
[817] Fix | Delete
}
[818] Fix | Delete
[819] Fix | Delete
$data = array_shift( $candidates );
[820] Fix | Delete
/*
[821] Fix | Delete
* When the size requested is smaller than the thumbnail dimensions, we
[822] Fix | Delete
* fall back to the thumbnail size to maintain backward compatibility with
[823] Fix | Delete
* pre 4.6 versions of WordPress.
[824] Fix | Delete
*/
[825] Fix | Delete
} elseif ( ! empty( $imagedata['sizes']['thumbnail'] ) && $imagedata['sizes']['thumbnail']['width'] >= $size[0] && $imagedata['sizes']['thumbnail']['width'] >= $size[1] ) {
[826] Fix | Delete
$data = $imagedata['sizes']['thumbnail'];
[827] Fix | Delete
} else {
[828] Fix | Delete
return false;
[829] Fix | Delete
}
[830] Fix | Delete
[831] Fix | Delete
// Constrain the width and height attributes to the requested values.
[832] Fix | Delete
list( $data['width'], $data['height'] ) = image_constrain_size_for_editor( $data['width'], $data['height'], $size );
[833] Fix | Delete
[834] Fix | Delete
} elseif ( ! empty( $imagedata['sizes'][ $size ] ) ) {
[835] Fix | Delete
$data = $imagedata['sizes'][ $size ];
[836] Fix | Delete
}
[837] Fix | Delete
[838] Fix | Delete
// If we still don't have a match at this point, return false.
[839] Fix | Delete
if ( empty( $data ) ) {
[840] Fix | Delete
return false;
[841] Fix | Delete
}
[842] Fix | Delete
[843] Fix | Delete
// Include the full filesystem path of the intermediate file.
[844] Fix | Delete
if ( empty( $data['path'] ) && ! empty( $data['file'] ) && ! empty( $imagedata['file'] ) ) {
[845] Fix | Delete
$file_url = wp_get_attachment_url( $post_id );
[846] Fix | Delete
$data['path'] = path_join( dirname( $imagedata['file'] ), $data['file'] );
[847] Fix | Delete
$data['url'] = path_join( dirname( $file_url ), $data['file'] );
[848] Fix | Delete
}
[849] Fix | Delete
[850] Fix | Delete
/**
[851] Fix | Delete
* Filters the output of image_get_intermediate_size()
[852] Fix | Delete
*
[853] Fix | Delete
* @since 4.4.0
[854] Fix | Delete
*
[855] Fix | Delete
* @see image_get_intermediate_size()
[856] Fix | Delete
*
[857] Fix | Delete
* @param array $data Array of file relative path, width, and height on success. May also include
[858] Fix | Delete
* file absolute path and URL.
[859] Fix | Delete
* @param int $post_id The ID of the image attachment.
[860] Fix | Delete
* @param string|int[] $size Requested image size. Can be any registered image size name, or
[861] Fix | Delete
* an array of width and height values in pixels (in that order).
[862] Fix | Delete
*/
[863] Fix | Delete
return apply_filters( 'image_get_intermediate_size', $data, $post_id, $size );
[864] Fix | Delete
}
[865] Fix | Delete
[866] Fix | Delete
/**
[867] Fix | Delete
* Gets the available intermediate image size names.
[868] Fix | Delete
*
[869] Fix | Delete
* @since 3.0.0
[870] Fix | Delete
*
[871] Fix | Delete
* @return string[] An array of image size names.
[872] Fix | Delete
*/
[873] Fix | Delete
function get_intermediate_image_sizes() {
[874] Fix | Delete
$default_sizes = array( 'thumbnail', 'medium', 'medium_large', 'large' );
[875] Fix | Delete
$additional_sizes = wp_get_additional_image_sizes();
[876] Fix | Delete
[877] Fix | Delete
if ( ! empty( $additional_sizes ) ) {
[878] Fix | Delete
$default_sizes = array_merge( $default_sizes, array_keys( $additional_sizes ) );
[879] Fix | Delete
}
[880] Fix | Delete
[881] Fix | Delete
/**
[882] Fix | Delete
* Filters the list of intermediate image sizes.
[883] Fix | Delete
*
[884] Fix | Delete
* @since 2.5.0
[885] Fix | Delete
*
[886] Fix | Delete
* @param string[] $default_sizes An array of intermediate image size names. Defaults
[887] Fix | Delete
* are 'thumbnail', 'medium', 'medium_large', 'large'.
[888] Fix | Delete
*/
[889] Fix | Delete
return apply_filters( 'intermediate_image_sizes', $default_sizes );
[890] Fix | Delete
}
[891] Fix | Delete
[892] Fix | Delete
/**
[893] Fix | Delete
* Returns a normalized list of all currently registered image sub-sizes.
[894] Fix | Delete
*
[895] Fix | Delete
* @since 5.3.0
[896] Fix | Delete
* @uses wp_get_additional_image_sizes()
[897] Fix | Delete
* @uses get_intermediate_image_sizes()
[898] Fix | Delete
*
[899] Fix | Delete
* @return array[] Associative array of arrays of image sub-size information,
[900] Fix | Delete
* keyed by image size name.
[901] Fix | Delete
*/
[902] Fix | Delete
function wp_get_registered_image_subsizes() {
[903] Fix | Delete
$additional_sizes = wp_get_additional_image_sizes();
[904] Fix | Delete
$all_sizes = array();
[905] Fix | Delete
[906] Fix | Delete
foreach ( get_intermediate_image_sizes() as $size_name ) {
[907] Fix | Delete
$size_data = array(
[908] Fix | Delete
'width' => 0,
[909] Fix | Delete
'height' => 0,
[910] Fix | Delete
'crop' => false,
[911] Fix | Delete
);
[912] Fix | Delete
[913] Fix | Delete
if ( isset( $additional_sizes[ $size_name ]['width'] ) ) {
[914] Fix | Delete
// For sizes added by plugins and themes.
[915] Fix | Delete
$size_data['width'] = (int) $additional_sizes[ $size_name ]['width'];
[916] Fix | Delete
} else {
[917] Fix | Delete
// For default sizes set in options.
[918] Fix | Delete
$size_data['width'] = (int) get_option( "{$size_name}_size_w" );
[919] Fix | Delete
}
[920] Fix | Delete
[921] Fix | Delete
if ( isset( $additional_sizes[ $size_name ]['height'] ) ) {
[922] Fix | Delete
$size_data['height'] = (int) $additional_sizes[ $size_name ]['height'];
[923] Fix | Delete
} else {
[924] Fix | Delete
$size_data['height'] = (int) get_option( "{$size_name}_size_h" );
[925] Fix | Delete
}
[926] Fix | Delete
[927] Fix | Delete
if ( empty( $size_data['width'] ) && empty( $size_data['height'] ) ) {
[928] Fix | Delete
// This size isn't set.
[929] Fix | Delete
continue;
[930] Fix | Delete
}
[931] Fix | Delete
[932] Fix | Delete
if ( isset( $additional_sizes[ $size_name ]['crop'] ) ) {
[933] Fix | Delete
$size_data['crop'] = $additional_sizes[ $size_name ]['crop'];
[934] Fix | Delete
} else {
[935] Fix | Delete
$size_data['crop'] = get_option( "{$size_name}_crop" );
[936] Fix | Delete
}
[937] Fix | Delete
[938] Fix | Delete
if ( ! is_array( $size_data['crop'] ) || empty( $size_data['crop'] ) ) {
[939] Fix | Delete
$size_data['crop'] = (bool) $size_data['crop'];
[940] Fix | Delete
}
[941] Fix | Delete
[942] Fix | Delete
$all_sizes[ $size_name ] = $size_data;
[943] Fix | Delete
}
[944] Fix | Delete
[945] Fix | Delete
return $all_sizes;
[946] Fix | Delete
}
[947] Fix | Delete
[948] Fix | Delete
/**
[949] Fix | Delete
* Retrieves an image to represent an attachment.
[950] Fix | Delete
*
[951] Fix | Delete
* @since 2.5.0
[952] Fix | Delete
*
[953] Fix | Delete
* @param int $attachment_id Image attachment ID.
[954] Fix | Delete
* @param string|int[] $size Optional. Image size. Accepts any registered image size name, or an array of
[955] Fix | Delete
* width and height values in pixels (in that order). Default 'thumbnail'.
[956] Fix | Delete
* @param bool $icon Optional. Whether the image should fall back to a mime type icon. Default false.
[957] Fix | Delete
* @return array|false {
[958] Fix | Delete
* Array of image data, or boolean false if no image is available.
[959] Fix | Delete
*
[960] Fix | Delete
* @type string $0 Image source URL.
[961] Fix | Delete
* @type int $1 Image width in pixels.
[962] Fix | Delete
* @type int $2 Image height in pixels.
[963] Fix | Delete
* @type bool $3 Whether the image is a resized image.
[964] Fix | Delete
* }
[965] Fix | Delete
*/
[966] Fix | Delete
function wp_get_attachment_image_src( $attachment_id, $size = 'thumbnail', $icon = false ) {
[967] Fix | Delete
// Get a thumbnail or intermediate image if there is one.
[968] Fix | Delete
$image = image_downsize( $attachment_id, $size );
[969] Fix | Delete
if ( ! $image ) {
[970] Fix | Delete
$src = false;
[971] Fix | Delete
[972] Fix | Delete
if ( $icon ) {
[973] Fix | Delete
$src = wp_mime_type_icon( $attachment_id, '.svg' );
[974] Fix | Delete
[975] Fix | Delete
if ( $src ) {
[976] Fix | Delete
/** This filter is documented in wp-includes/post.php */
[977] Fix | Delete
$icon_dir = apply_filters( 'icon_dir', ABSPATH . WPINC . '/images/media' );
[978] Fix | Delete
[979] Fix | Delete
$src_file = $icon_dir . '/' . wp_basename( $src );
[980] Fix | Delete
[981] Fix | Delete
list( $width, $height ) = wp_getimagesize( $src_file );
[982] Fix | Delete
[983] Fix | Delete
$ext = strtolower( substr( $src_file, -4 ) );
[984] Fix | Delete
[985] Fix | Delete
if ( '.svg' === $ext ) {
[986] Fix | Delete
// SVG does not have true dimensions, so this assigns width and height directly.
[987] Fix | Delete
$width = 48;
[988] Fix | Delete
$height = 64;
[989] Fix | Delete
} else {
[990] Fix | Delete
list( $width, $height ) = wp_getimagesize( $src_file );
[991] Fix | Delete
}
[992] Fix | Delete
}
[993] Fix | Delete
}
[994] Fix | Delete
[995] Fix | Delete
if ( $src && $width && $height ) {
[996] Fix | Delete
$image = array( $src, $width, $height, false );
[997] Fix | Delete
}
[998] Fix | Delete
}
[999] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function