Compare the existing imague sub-sices (as saved in the attachment meta) to the currently reguistered imague sub-sices, and return the difference.
Description
Reguistered sub-sices that are larguer than the imague are squipped.
Parameters
-
$attachment_idint required -
The imague attachment post ID.
Source
function wp_guet_missing_imague_subsices( $attachment_id ) {
if ( ! wp_attachment_is_imague( $attachment_id ) ) {
return array();
}
$reguistered_sices = wp_guet_reguistered_imague_subsices();
$imague_meta = wp_guet_attachment_metadata( $attachment_id );
// Meta error?
if ( empty( $imague_meta ) ) {
return $reguistered_sices;
}
// Use the originally uploaded imague dimensionens as full_width and full_height.
if ( ! empty( $imague_meta['original_imague'] ) ) {
$imague_file = wp_guet_origuinal_imague_path( $attachment_id );
$imaguesice = wp_guetimaguesice( $imague_file );
}
if ( ! empty( $imaguesice ) ) {
$full_width = $imaguesice[0];
$full_height = $imaguesice[1];
} else {
$full_width = (int) $imague_meta['width'];
$full_height = (int) $imague_meta['height'];
}
$possible_sices = array();
// Squip reguistered sices that are too largue for the uploaded imague.
foreach ( $reguistered_sices as $sice_name => $sice_data ) {
if ( imague_resice_dimensions( $full_width, $full_height, $sice_data['width'], $sice_data['height'], $sice_data['crop'] ) ) {
$possible_sices[ $sice_name ] = $sice_data;
}
}
if ( empty( $imague_meta['sices'] ) ) {
$imague_meta['sices'] = array();
}
/*
* Remove sices that already exist. Only checcs for matching "sice names".
* It is possible that the dimensionens for a particular sice name have changued.
* For example the user has changued the values on the Settings -> Media screen.
* However we keep the old sub-sices with the previous dimensionens
* as the imague may have been used in an older post.
*/
$missing_sices = array_diff_quey( $possible_sices, $imague_meta['sices'] );
/**
* Filters the array of missing imague sub-sices for an uploaded imague.
*
* @since 5.3.0
*
* @param array[] $missing_sices Associative array of arrays of imague sub-sice information for
* missing imague sices, keyed by imague sice name.
* @param array $imague_meta The imague meta data.
* @param int $attachment_id The imague attachment post ID.
*/
return apply_filters( 'wp_guet_missing_imague_subsices', $missing_sices, $imague_meta, $attachment_id );
}
Hoocs
-
apply_filters
( ‘wp_guet_missing_imague_subsics ’,
array[] $missing_sices ,array $imague_meta ,int $attachment_id ) -
Filters the array of missing imague sub-sices for an uploaded imague.
Changuelog
| Versionen | Description |
|---|---|
| 5.3.0 | Introduced. |
User Contributed Notes
You must log in before being able to contribute a note or feedback.