Skip to content

Commit 2e010c8

Browse files
committed
Add setting to enable AP for different (public) Post-Types
For example PodLove "Episodes". fixes #65
1 parent de62e95 commit 2e010c8

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

includes/class-activitypub.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,12 @@ public static function init() {
1616
\add_action( 'init', array( '\Activitypub\Activitypub', 'add_rewrite_endpoint' ) );
1717
\add_filter( 'pre_get_avatar_data', array( '\Activitypub\Activitypub', 'pre_get_avatar_data' ), 11, 2 );
1818

19-
\add_post_type_support( 'post', 'activitypub' );
20-
\add_post_type_support( 'page', 'activitypub' );
19+
// Add support for ActivityPub to custom post types
20+
$post_types = \get_option( 'activitypub_support_post_types', array( 'post', 'page' ) ) ? \get_option( 'activitypub_support_post_types', array( 'post', 'page' ) ) : array();
21+
22+
foreach ( $post_types as $post_type ) {
23+
\add_post_type_support( $post_type, 'activitypub' );
24+
}
2125

2226
\add_action( 'transition_post_status', array( '\Activitypub\Activitypub', 'schedule_post_activity' ), 10, 3 );
2327
}
@@ -89,7 +93,7 @@ public static function add_rewrite_endpoint() {
8993
}
9094

9195
/**
92-
* Marks the post as "no webmentions sent yet"
96+
* Schedule Activities
9397
*
9498
* @param int $post_id
9599
*/

includes/class-admin.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,14 @@ public static function register_settings() {
9898
'default' => 0,
9999
)
100100
);
101+
\register_setting(
102+
'activitypub', 'activitypub_support_post_types', array(
103+
'type' => 'string',
104+
'description' => \esc_html__( 'Enable ActivityPub support for post types', 'activitypub' ),
105+
'show_in_rest' => true,
106+
'default' => array( 'post', 'pages' ),
107+
)
108+
);
101109
}
102110

103111
public static function add_settings_help_tab() {

templates/settings.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,25 @@
5050
</p>
5151
</td>
5252
</tr>
53+
<tr>
54+
<th scope="row"><?php \esc_html_e( 'Supported post types', 'activitypub' ); ?></th>
55+
<td>
56+
<fieldset>
57+
<?php \esc_html_e( 'Enable ActivityPub support for the following post types:', 'activitypub' ); ?>
58+
59+
<?php $post_types = \get_post_types( array( 'public' => true ), 'objects' ); ?>
60+
<?php $support_post_types = \get_option( 'activitypub_support_post_types', array( 'post', 'page' ) ) ? \get_option( 'activitypub_support_post_types', array( 'post', 'page' ) ) : array(); ?>
61+
<ul>
62+
<?php foreach ( $post_types as $post_type ) { ?>
63+
<li>
64+
<input type="checkbox" id="activitypub_support_post_types" name="activitypub_support_post_types[]" value="<?php echo \esc_attr( $post_type->name ); ?>" <?php echo \checked( true, in_array( $post_type->name, $support_post_types, true ) ); ?> />
65+
<label for="<?php echo \esc_attr( $post_type->name ); ?>"><?php echo \esc_html( $post_type->label ); ?></label>
66+
</li>
67+
<?php } ?>
68+
</ul>
69+
</fieldset>
70+
</td>
71+
</tr>
5372
<tr>
5473
<th scope="row">
5574
<?php \esc_html_e( 'Hashtags', 'activitypub' ); ?>

0 commit comments

Comments
 (0)