simplified ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS

This commit is contained in:
Matthias Pfefferle 2023-01-12 21:55:33 +01:00 committed by GitHub
parent 1e7e6bba28
commit 6992fbbe22
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -82,7 +82,7 @@ class Post {
// max images can't be negative or zero // max images can't be negative or zero
if ( $max_images <= 0 ) { if ( $max_images <= 0 ) {
$max_images = 1; return $images;
} }
$id = $this->post->ID; $id = $this->post->ID;
@ -94,22 +94,20 @@ class Post {
$max_images--; $max_images--;
} }
// then list any image attachments // then list any image attachments
if ( $max_images > 0 ) { $query = new \WP_Query(
$query = new \WP_Query( array(
array( 'post_parent' => $id,
'post_parent' => $id, 'post_status' => 'inherit',
'post_status' => 'inherit', 'post_type' => 'attachment',
'post_type' => 'attachment', 'post_mime_type' => 'image',
'post_mime_type' => 'image', 'order' => 'ASC',
'order' => 'ASC', 'orderby' => 'menu_order ID',
'orderby' => 'menu_order ID', 'posts_per_page' => $max_images,
'posts_per_page' => $max_images, )
) );
); foreach ( $query->get_posts() as $attachment ) {
foreach ( $query->get_posts() as $attachment ) { if ( ! \in_array( $attachment->ID, $image_ids, true ) ) {
if ( ! \in_array( $attachment->ID, $image_ids, true ) ) { $image_ids[] = $attachment->ID;
$image_ids[] = $attachment->ID;
}
} }
} }