' );
\defined( 'ACTIVITYPUB_CUSTOM_POST_CONTENT' ) || \define( 'ACTIVITYPUB_CUSTOM_POST_CONTENT', "%title%
\n\n%content%\n\n%hashtags%
\n\n%shortlink%
" );
diff --git a/includes/class-admin.php b/includes/class-admin.php
index 3354df1..0481cbb 100644
--- a/includes/class-admin.php
+++ b/includes/class-admin.php
@@ -98,6 +98,15 @@ class Admin {
'default' => ACTIVITYPUB_CUSTOM_POST_CONTENT,
)
);
+ \register_setting(
+ 'activitypub',
+ 'activitypub_max_image_attachments',
+ array(
+ 'type' => 'integer',
+ 'description' => \__( 'Number of images to attach to posts.', 'activitypub' ),
+ 'default' => ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS,
+ )
+ );
\register_setting(
'activitypub',
'activitypub_object_type',
diff --git a/includes/model/class-post.php b/includes/model/class-post.php
index cd8f119..80c4d25 100644
--- a/includes/model/class-post.php
+++ b/includes/model/class-post.php
@@ -80,38 +80,42 @@ class Post {
}
public function generate_attachments() {
- $max_images = \apply_filters( 'activitypub_max_images', 3 );
+ $max_images = intval( \apply_filters( 'activitypub_max_image_attachments', \get_option( 'activitypub_max_image_attachments', ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS ) ) );
$images = array();
// max images can't be negative or zero
if ( $max_images <= 0 ) {
- $max_images = 1;
+ return $images;
}
$id = $this->post->ID;
$image_ids = array();
+
// list post thumbnail first if this post has one
if ( \function_exists( 'has_post_thumbnail' ) && \has_post_thumbnail( $id ) ) {
$image_ids[] = \get_post_thumbnail_id( $id );
$max_images--;
}
- // then list any image attachments
- $query = new \WP_Query(
- array(
- 'post_parent' => $id,
- 'post_status' => 'inherit',
- 'post_type' => 'attachment',
- 'post_mime_type' => 'image',
- 'order' => 'ASC',
- 'orderby' => 'menu_order ID',
- 'posts_per_page' => $max_images,
- )
- );
- foreach ( $query->get_posts() as $attachment ) {
- if ( ! \in_array( $attachment->ID, $image_ids, true ) ) {
- $image_ids[] = $attachment->ID;
+
+ if ( $max_images > 0 ) {
+ // then list any image attachments
+ $query = new \WP_Query(
+ array(
+ 'post_parent' => $id,
+ 'post_status' => 'inherit',
+ 'post_type' => 'attachment',
+ 'post_mime_type' => 'image',
+ 'order' => 'ASC',
+ 'orderby' => 'menu_order ID',
+ 'posts_per_page' => $max_images,
+ )
+ );
+ foreach ( $query->get_posts() as $attachment ) {
+ if ( ! \in_array( $attachment->ID, $image_ids, true ) ) {
+ $image_ids[] = $attachment->ID;
+ }
}
}
diff --git a/templates/settings.php b/templates/settings.php
index 4bcb358..9450195 100644
--- a/templates/settings.php
+++ b/templates/settings.php
@@ -74,6 +74,26 @@
Let me know