configuration item for number of images to attach
This commit is contained in:
parent
7d5b8e7a82
commit
d1765b56dd
4 changed files with 47 additions and 15 deletions
|
@ -19,6 +19,7 @@ namespace Activitypub;
|
|||
* Initialize plugin
|
||||
*/
|
||||
function init() {
|
||||
\defined( 'ACTIVITYPUB_NUMBER_IMAGES' ) || \define( 'ACTIVITYPUB_NUMBER_IMAGES', 3 );
|
||||
\defined( 'ACTIVITYPUB_HASHTAGS_REGEXP' ) || \define( 'ACTIVITYPUB_HASHTAGS_REGEXP', '(?:(?<=\s)|(?<=<p>)|(?<=<br>)|^)#([A-Za-z0-9_]+)(?:(?=\s|[[:punct:]]|$))' );
|
||||
\defined( 'ACTIVITYPUB_ALLOWED_HTML' ) || \define( 'ACTIVITYPUB_ALLOWED_HTML', '<strong><a><p><ul><ol><li><code><blockquote><pre><img>' );
|
||||
\defined( 'ACTIVITYPUB_CUSTOM_POST_CONTENT' ) || \define( 'ACTIVITYPUB_CUSTOM_POST_CONTENT', "<p><strong>%title%</strong></p>\n\n%content%\n\n<p>%hashtags%</p>\n\n<p>%shortlink%</p>" );
|
||||
|
|
|
@ -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',
|
||||
|
|
|
@ -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,6 +94,7 @@ class Post {
|
|||
$max_images--;
|
||||
}
|
||||
// then list any image attachments
|
||||
if ( $max_images > 0 ) {
|
||||
$query = new \WP_Query(
|
||||
array(
|
||||
'post_parent' => $id,
|
||||
|
@ -110,6 +111,7 @@ class Post {
|
|||
$image_ids[] = $attachment->ID;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$image_ids = \array_unique( $image_ids );
|
||||
|
||||
|
|
|
@ -74,6 +74,26 @@
|
|||
<p><?php echo \wp_kses( \__( '<a href="https://github.com/pfefferle/wordpress-activitypub/issues/new" target="_blank">Let me know</a> if you miss a template pattern.', 'activitypub' ), 'default' ); ?></p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">
|
||||
<?php \esc_html_e( 'Number of images', 'activitypub' ); ?>
|
||||
</th>
|
||||
<td>
|
||||
<textarea name="activitypub_number_images" id="activitypub_number_images" rows="1" cols="50" class="large-text"><?php echo esc_html( \get_option( 'activitypub_number_images', ACTIVITYPUB_NUMBER_IMAGES ) ); ?></textarea>
|
||||
<p class="description">
|
||||
<?php
|
||||
echo \wp_kses(
|
||||
\sprintf(
|
||||
// translators:
|
||||
\__( 'The number of images to attach to posts. Default: <code>%s</code>', 'activitypub' ),
|
||||
\esc_html( ACTIVITYPUB_NUMBER_IMAGES )
|
||||
),
|
||||
'default'
|
||||
);
|
||||
?>
|
||||
</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="row">
|
||||
<?php \esc_html_e( 'Activity-Object-Type', 'activitypub' ); ?>
|
||||
|
|
Loading…
Reference in a new issue