Skip to content

Commit

Permalink
Improve attachment handling (#751)
Browse files Browse the repository at this point in the history
  • Loading branch information
pfefferle committed May 2, 2024
1 parent cdd303c commit 60d6be0
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions includes/transformer/class-post.php
Expand Up @@ -249,7 +249,7 @@ protected function get_classic_editor_image_embeds( $max_images ) {
// This linter warning is a false positive - we have to
// re-count each time here as we modify $images.
// phpcs:ignore Squiz.PHP.DisallowSizeFunctionsInLoops.Found
while ( $tags->next_tag( 'img' ) && ( \count( $images ) < $max_images ) ) {
while ( $tags->next_tag( 'img' ) && ( \count( $images ) <= $max_images ) ) {
$src = $tags->get_attribute( 'src' );

// If the img source is in our uploads dir, get the
Expand Down Expand Up @@ -311,7 +311,7 @@ protected function get_classic_editor_images( $max_images ) {
$images[] = \get_post_thumbnail_id( $id );
}

if ( \count( $images ) < $max_images ) {
if ( \count( $images ) <= $max_images ) {
if ( \class_exists( '\WP_HTML_Tag_Processor' ) ) {
$images = \array_merge( $images, $this->get_classic_editor_image_embeds( $max_images ) );
} else {
Expand Down Expand Up @@ -427,14 +427,14 @@ public static function wp_attachment_to_activity_attachment( $media ) {
// switching on image/audio/video
switch ( $mime_type_parts[0] ) {
case 'image':
$image_size = 'full';
$image_size = 'large';

/**
* Filter the image URL returned for each post.
*
* @param array|false $thumbnail The image URL, or false if no image is available.
* @param int $id The attachment ID.
* @param string $image_size The image size to retrieve. Set to 'full' by default.
* @param string $image_size The image size to retrieve. Set to 'large' by default.
*/
$thumbnail = apply_filters(
'activitypub_get_image',
Expand Down Expand Up @@ -488,16 +488,16 @@ public static function wp_attachment_to_activity_attachment( $media ) {
* Return details about an image attachment.
*
* @param int $id The attachment ID.
* @param string $image_size The image size to retrieve. Set to 'full' by default.
* @param string $image_size The image size to retrieve. Set to 'large' by default.
*
* @return array|false Array of image data, or boolean false if no image is available.
*/
protected static function get_wordpress_attachment( $id, $image_size = 'full' ) {
protected static function get_wordpress_attachment( $id, $image_size = 'large' ) {
/**
* Hook into the image retrieval process. Before image retrieval.
*
* @param int $id The attachment ID.
* @param string $image_size The image size to retrieve. Set to 'full' by default.
* @param string $image_size The image size to retrieve. Set to 'large' by default.
*/
do_action( 'activitypub_get_image_pre', $id, $image_size );

Expand All @@ -507,7 +507,7 @@ protected static function get_wordpress_attachment( $id, $image_size = 'full' )
* Hook into the image retrieval process. After image retrieval.
*
* @param int $id The attachment ID.
* @param string $image_size The image size to retrieve. Set to 'full' by default.
* @param string $image_size The image size to retrieve. Set to 'large' by default.
*/
do_action( 'activitypub_get_image_post', $id, $image_size );

Expand Down

0 comments on commit 60d6be0

Please sign in to comment.