$attachment_ids Id вложений. * @param int $limit Сколько id брать в рассмотрение. * @return int[] */ public static function image_ids( array $attachment_ids, int $limit ): array { $ids = array(); foreach ( array_slice( $attachment_ids, 0, $limit ) as $attachment_id ) { $attachment_id = (int) $attachment_id; if ( $attachment_id > 0 && ! in_array( $attachment_id, $ids, true ) && 'attachment' === get_post_type( $attachment_id ) && wp_attachment_is_image( $attachment_id ) ) { $ids[] = $attachment_id; } } return $ids; } /** * Адрес миниатюры вложения для окна; пустая строка — адреса нет. * * @param int $attachment_id Id вложения. * @return string */ public static function thumb_url( int $attachment_id ): string { return (string) wp_get_attachment_image_url( $attachment_id, self::THUMB_SIZE ); } /** * Адрес картинки в полный размер — для просмотра в окне (лупа на слоте): человек видит * тот же файл, что уходит в фотосессию, а не миниатюру. Оригинал, если WordPress хранит * его отдельно от уменьшенной копии «-scaled», иначе — сам файл вложения; '' — адреса нет. * * @param int $attachment_id Id вложения. * @return string */ public static function full_url( int $attachment_id ): string { $url = wp_get_original_image_url( $attachment_id ); return is_string( $url ) && '' !== $url ? $url : (string) wp_get_attachment_url( $attachment_id ); } /** * Имя файла вложения — окно показывает его, если миниатюра не загрузилась. * * @param int $attachment_id Id вложения. * @return string */ public static function file_name( int $attachment_id ): string { $path = (string) get_attached_file( $attachment_id ); if ( '' === $path ) { $path = (string) wp_parse_url( (string) wp_get_attachment_url( $attachment_id ), PHP_URL_PATH ); } return wp_basename( $path ); } }