' );
\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..ecb7f73 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_number_images',
+ array(
+ 'type' => 'integer',
+ 'description' => \__( 'Number of images to attach to posts.', 'activitypub' ),
+ 'default' => ACTIVITYPUB_NUMBER_IMAGES,
+ )
+ );
\register_setting(
'activitypub',
'activitypub_object_type',
diff --git a/includes/model/class-post.php b/includes/model/class-post.php
index e885199..832f742 100644
--- a/includes/model/class-post.php
+++ b/includes/model/class-post.php
@@ -76,7 +76,7 @@ class Post {
}
public function generate_attachments() {
- $max_images = \apply_filters( 'activitypub_max_images', 3 );
+ $max_images = intval( \apply_filters( 'activitypub_max_images', \get_option( 'activitypub_number_images', ACTIVITYPUB_NUMBER_IMAGES ) ) );
$images = array();
@@ -94,20 +94,22 @@ class Post {
$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 ) {
+ $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..90a1503 100644
--- a/templates/settings.php
+++ b/templates/settings.php
@@ -74,6 +74,26 @@
Let me know