*/ public static function for_post( int $post_id ): array { $featured_id = (int) get_post_thumbnail_id( $post_id ); $children = get_children( array( 'post_parent' => $post_id, 'post_type' => 'attachment', 'numberposts' => 12, ) ); $images = array(); $seen = array(); foreach ( (array) $children as $attachment ) { $att_id = (int) ( $attachment->ID ?? 0 ); if ( $att_id <= 0 ) { continue; } $role = (string) get_post_meta( $att_id, '_prautoblogger_image_role', true ); if ( '' === $role && $att_id !== $featured_id ) { continue; // Not a pipeline attachment. } $url = (string) wp_get_attachment_image_url( $att_id, 'medium' ); if ( '' === $url ) { continue; } $seen[ $att_id ] = true; $images[] = array( 'id' => $att_id, 'role' => '' !== $role ? $role : 'featured', 'url' => $url, 'is_featured' => $att_id === $featured_id, ); } // Featured image attached elsewhere (not a child) still renders. if ( $featured_id > 0 && ! isset( $seen[ $featured_id ] ) ) { $url = (string) wp_get_attachment_image_url( $featured_id, 'medium' ); if ( '' !== $url ) { $images[] = array( 'id' => $featured_id, 'role' => 'featured', 'url' => $url, 'is_featured' => true, ); } } return $images; } }