PluginProbe
ActivityPub / 8.0.2
ActivityPub v8.0.2
9.3.1 9.3.0 9.2.2 9.2.1 9.2.0 9.1.0 9.0.2 9.0.1 9.0.0 8.3.0 8.2.1 8.2.0 8.1.1 1.0.5 1.0.6 1.0.7 1.0.8 1.0.9 1.1.0 1.2.0 1.3.0 2.0.0 2.0.1 2.1.0 2.1.1 All 160 releases
← All changes | includes/class-activitypub.php +249 -353 2.0.18.0.2 View file →
@@ -1,18 +1,19 @@
1 1 <?php
2 +/**
3 + * ActivityPub Class.
4 + *
5 + * @package Activitypub
6 + */
7 +
2 8 namespace Activitypub;
3 9
4 -use Exception;
5 -use Activitypub\Signature;
6 -use Activitypub\Collection\Users;
7 10 use Activitypub\Collection\Followers;
11 +use Activitypub\Collection\Following;
12 +use Activitypub\Collection\Posts;
8 13
9 -use function Activitypub\sanitize_url;
10 -use function Activitypub\is_comment;
11 -use function Activitypub\is_activitypub_request;
12 -
13 14 /**
14 - * ActivityPub Class
15 + * ActivityPub Class.
15 16 *
16 17 * @author Matthias Pfefferle
17 18 */
18 19 class Activitypub {
@@ -19,235 +20,76 @@
19 20 /**
20 21 * Initialize the class, registering WordPress hooks.
21 22 */
22 23 public static function init() {
23 - \add_filter( 'template_include', array( self::class, 'render_json_template' ), 99 );
24 - \add_action( 'template_redirect', array( self::class, 'template_redirect' ) );
25 - \add_filter( 'query_vars', array( self::class, 'add_query_vars' ) );
26 - \add_filter( 'pre_get_avatar_data', array( self::class, 'pre_get_avatar_data' ), 11, 2 );
27 - \add_filter( 'get_comment_link', array( self::class, 'remote_comment_link' ), 11, 3 );
24 + \add_action( 'init', array( self::class, 'theme_compat' ), 11 );
25 + \add_action( 'init', array( self::class, 'register_user_meta' ), 11 );
28 26
29 - // Add support for ActivityPub to custom post types
30 - $post_types = \get_option( 'activitypub_support_post_types', array( 'post', 'page' ) ) ? \get_option( 'activitypub_support_post_types', array( 'post', 'page' ) ) : array();
31 -
32 - foreach ( $post_types as $post_type ) {
33 - \add_post_type_support( $post_type, 'activitypub' );
34 - }
35 -
36 27 \add_action( 'wp_trash_post', array( self::class, 'trash_post' ), 1 );
37 28 \add_action( 'untrash_post', array( self::class, 'untrash_post' ), 1 );
38 29
39 - \add_action( 'init', array( self::class, 'add_rewrite_rules' ), 11 );
30 + \add_action( 'user_register', array( self::class, 'user_register' ) );
40 31
41 - \add_action( 'after_setup_theme', array( self::class, 'theme_compat' ), 99 );
42 -
43 - \add_action( 'in_plugin_update_message-' . ACTIVITYPUB_PLUGIN_BASENAME, array( self::class, 'plugin_update_message' ) );
44 -
45 - \add_filter( 'comment_class', array( self::class, 'comment_class' ), 10, 3 );
46 -
47 - // register several post_types
48 - self::register_post_types();
32 + \add_action( 'activitypub_add_user_block', array( Followers::class, 'remove_blocked_actors' ), 10, 3 );
33 + \add_action( 'activitypub_add_user_block', array( Following::class, 'remove_blocked_actors' ), 10, 3 );
49 34 }
50 35
51 36 /**
52 - * Activation Hook
37 + * Activation Hook.
53 38 *
54 - * @return void
39 + * @param bool $network_wide Whether to activate the plugin for all sites in the network or just the current site.
55 40 */
56 - public static function activate() {
41 + public static function activate( $network_wide ) {
57 42 self::flush_rewrite_rules();
58 43 Scheduler::register_schedules();
59 - }
60 44
61 - /**
62 - * Deactivation Hook
63 - *
64 - * @return void
65 - */
66 - public static function deactivate() {
67 - self::flush_rewrite_rules();
68 - Scheduler::deregister_schedules();
69 - }
45 + \add_filter( 'pre_wp_update_comment_count_now', array( Comment::class, 'pre_wp_update_comment_count_now' ), 5, 3 );
46 + Migration::update_comment_counts();
70 47
71 - /**
72 - * Uninstall Hook
73 - *
74 - * @return void
75 - */
76 - public static function uninstall() {
77 - Scheduler::deregister_schedules();
78 - }
79 -
80 - /**
81 - * Return a AS2 JSON version of an author, post or page.
82 - *
83 - * @param string $template The path to the template object.
84 - *
85 - * @return string The new path to the JSON template.
86 - */
87 - public static function render_json_template( $template ) {
88 - if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) {
89 - return $template;
90 - }
91 -
92 - if ( ! is_activitypub_request() ) {
93 - return $template;
94 - }
95 -
96 - $json_template = false;
97 -
98 - // check if user can publish posts
99 - if ( \is_author() && is_wp_error( Users::get_by_id( \get_the_author_meta( 'ID' ) ) ) ) {
100 - return $template;
101 - }
102 -
103 - if ( \is_author() ) {
104 - $json_template = ACTIVITYPUB_PLUGIN_DIR . '/templates/author-json.php';
105 - } elseif ( is_comment() ) {
106 - $json_template = ACTIVITYPUB_PLUGIN_DIR . '/templates/comment-json.php';
107 - } elseif ( \is_singular() ) {
108 - $json_template = ACTIVITYPUB_PLUGIN_DIR . '/templates/post-json.php';
109 - } elseif ( \is_home() ) {
110 - $json_template = ACTIVITYPUB_PLUGIN_DIR . '/templates/blog-json.php';
111 - }
112 -
113 - if ( ACTIVITYPUB_AUTHORIZED_FETCH ) {
114 - $verification = Signature::verify_http_signature( $_SERVER );
115 - if ( \is_wp_error( $verification ) ) {
116 - // fallback as template_loader can't return http headers
117 - return $template;
48 + if ( \is_multisite() && $network_wide && ! \wp_is_large_network() ) {
49 + $sites = \get_sites( array( 'fields' => 'ids' ) );
50 + foreach ( $sites as $site ) {
51 + \switch_to_blog( $site );
52 + self::flush_rewrite_rules();
53 + \restore_current_blog();
118 54 }
119 55 }
120 -
121 - return $json_template;
122 56 }
123 57
124 58 /**
125 - * Custom redirects for ActivityPub requests.
59 + * Deactivation Hook.
126 60 *
127 - * @return void
61 + * @param bool $network_wide Whether to deactivate the plugin for all sites in the network or just the current site.
128 62 */
129 - public static function template_redirect() {
130 - $comment_id = get_query_var( 'c', null );
63 + public static function deactivate( $network_wide ) {
64 + self::flush_rewrite_rules();
65 + Scheduler::deregister_schedules();
131 66
132 - // check if it seems to be a comment
133 - if ( ! $comment_id ) {
134 - return;
135 - }
67 + \remove_filter( 'pre_wp_update_comment_count_now', array( Comment::class, 'pre_wp_update_comment_count_now' ), 5 );
68 + Migration::update_comment_counts( 2000 );
136 69
137 - $comment = get_comment( $comment_id );
138 -
139 - // load a 404 page if `c` is set but not valid
140 - if ( ! $comment ) {
141 - global $wp_query;
142 - $wp_query->set_404();
143 - return;
144 - }
145 -
146 - // stop if it's not an ActivityPub comment
147 - if ( is_activitypub_request() && $comment->user_id ) {
148 - return;
149 - }
150 -
151 - wp_safe_redirect( get_comment_link( $comment ) );
152 - exit;
153 - }
154 -
155 - /**
156 - * Add the 'activitypub' query variable so WordPress won't mangle it.
157 - */
158 - public static function add_query_vars( $vars ) {
159 - $vars[] = 'activitypub';
160 - $vars[] = 'c';
161 - $vars[] = 'p';
162 -
163 - return $vars;
164 - }
165 -
166 - /**
167 - * Replaces the default avatar.
168 - *
169 - * @param array $args Arguments passed to get_avatar_data(), after processing.
170 - * @param int|string|object $id_or_email A user ID, email address, or comment object.
171 - *
172 - * @return array $args
173 - */
174 - public static function pre_get_avatar_data( $args, $id_or_email ) {
175 - if (
176 - ! $id_or_email instanceof \WP_Comment ||
177 - ! isset( $id_or_email->comment_type ) ||
178 - $id_or_email->user_id
179 - ) {
180 - return $args;
181 - }
182 -
183 - $allowed_comment_types = \apply_filters( 'get_avatar_comment_types', array( 'comment' ) );
184 - if (
185 - ! empty( $id_or_email->comment_type ) &&
186 - ! \in_array(
187 - $id_or_email->comment_type,
188 - (array) $allowed_comment_types,
189 - true
190 - )
191 - ) {
192 - $args['url'] = false;
193 - /** This filter is documented in wp-includes/link-template.php */
194 - return \apply_filters( 'get_avatar_data', $args, $id_or_email );
195 - }
196 -
197 - // Check if comment has an avatar.
198 - $avatar = self::get_avatar_url( $id_or_email->comment_ID );
199 -
200 - if ( $avatar ) {
201 - if ( ! isset( $args['class'] ) || ! \is_array( $args['class'] ) ) {
202 - $args['class'] = array( 'u-photo' );
203 - } else {
204 - $args['class'][] = 'u-photo';
205 - $args['class'] = \array_unique( $args['class'] );
70 + if ( \is_multisite() && $network_wide && ! \wp_is_large_network() ) {
71 + $sites = \get_sites( array( 'fields' => 'ids' ) );
72 + foreach ( $sites as $site ) {
73 + \switch_to_blog( $site );
74 + self::flush_rewrite_rules();
75 + \restore_current_blog();
206 76 }
207 - $args['url'] = $avatar;
208 - $args['class'][] = 'avatar-activitypub';
209 77 }
210 -
211 - return $args;
212 78 }
213 79
214 80 /**
215 - * Function to retrieve Avatar URL if stored in meta.
216 - *
217 - * @param int|WP_Comment $comment
218 - *
219 - * @return string $url
81 + * Uninstall Hook.
220 82 */
221 - public static function get_avatar_url( $comment ) {
222 - if ( \is_numeric( $comment ) ) {
223 - $comment = \get_comment( $comment );
224 - }
225 - return \get_comment_meta( $comment->comment_ID, 'avatar_url', true );
226 - }
83 + public static function uninstall() {
84 + Scheduler::deregister_schedules();
227 85
228 - /**
229 - * Link remote comments to source url.
230 - *
231 - * @param string $comment_link
232 - * @param object|WP_Comment $comment
233 - *
234 - * @return string $url
235 - */
236 - public static function remote_comment_link( $comment_link, $comment ) {
237 - if ( ! $comment || is_admin() ) {
238 - return $comment_link;
239 - }
86 + \remove_filter( 'pre_wp_update_comment_count_now', array( Comment::class, 'pre_wp_update_comment_count_now' ), 5 );
87 + Migration::update_comment_counts( 2000 );
240 88
241 - $comment_meta = \get_comment_meta( $comment->comment_ID );
89 + Posts::delete_all();
242 90
243 - if ( ! empty( $comment_meta['source_url'][0] ) ) {
244 - return $comment_meta['source_url'][0];
245 - } elseif ( ! empty( $comment_meta['source_id'][0] ) ) {
246 - return $comment_meta['source_id'][0];
247 - }
248 -
249 - return $comment_link;
91 + Options::delete();
250 92 }
251 93
252 94 /**
253 95 * Store permalink in meta, to send delete Activity.
@@ -252,15 +94,13 @@
252 94 /**
253 95 * Store permalink in meta, to send delete Activity.
254 96 *
255 97 * @param string $post_id The Post ID.
256 - *
257 - * @return void
258 98 */
259 99 public static function trash_post( $post_id ) {
260 100 \add_post_meta(
261 101 $post_id,
262 - 'activitypub_canonical_url',
102 + '_activitypub_canonical_url',
263 103 \get_permalink( $post_id ),
264 104 true
265 105 );
266 106 }
@@ -265,214 +105,270 @@
265 105 );
266 106 }
267 107
268 108 /**
269 - * Delete permalink from meta
109 + * Delete permalink from meta.
270 110 *
271 - * @param string $post_id The Post ID
272 - *
273 - * @return void
111 + * @param string $post_id The Post ID.
274 112 */
275 113 public static function untrash_post( $post_id ) {
276 - \delete_post_meta( $post_id, 'activitypub_canonical_url' );
114 + \delete_post_meta( $post_id, '_activitypub_canonical_url' );
277 115 }
278 116
279 117 /**
280 - * Add rewrite rules
118 + * Flush rewrite rules.
281 119 */
120 + public static function flush_rewrite_rules() {
121 + Router::add_rewrite_rules();
122 + \flush_rewrite_rules();
123 + }
124 +
125 + /**
126 + * Add rewrite rules.
127 + *
128 + * @deprecated 7.5.0 Use {@see Router::add_rewrite_rules()}.
129 + */
282 130 public static function add_rewrite_rules() {
283 - // If another system needs to take precedence over the ActivityPub rewrite rules,
284 - // they can define their own and will manually call the appropriate functions as required.
285 - if ( ACTIVITYPUB_DISABLE_REWRITES ) {
286 - return;
287 - }
131 + _deprecated_function( __FUNCTION__, '7.5.0', '\Activitypub\Router::add_rewrite_rules()' );
288 132
289 - if ( ! \class_exists( 'Webfinger' ) ) {
290 - \add_rewrite_rule(
291 - '^.well-known/webfinger',
292 - 'index.php?rest_route=/' . ACTIVITYPUB_REST_NAMESPACE . '/webfinger',
293 - 'top'
294 - );
295 - }
296 -
297 - if ( ! \class_exists( 'Nodeinfo_Endpoint' ) && true === (bool) \get_option( 'blog_public', 1 ) ) {
298 - \add_rewrite_rule(
299 - '^.well-known/nodeinfo',
300 - 'index.php?rest_route=/' . ACTIVITYPUB_REST_NAMESPACE . '/nodeinfo/discovery',
301 - 'top'
302 - );
303 - \add_rewrite_rule(
304 - '^.well-known/x-nodeinfo2',
305 - 'index.php?rest_route=/' . ACTIVITYPUB_REST_NAMESPACE . '/nodeinfo2',
306 - 'top'
307 - );
308 - }
309 -
310 - \add_rewrite_rule(
311 - '^@([\w\-\.]+)',
312 - 'index.php?rest_route=/' . ACTIVITYPUB_REST_NAMESPACE . '/users/$matches[1]',
313 - 'top'
314 - );
315 -
316 - \add_rewrite_endpoint( 'activitypub', EP_AUTHORS | EP_PERMALINK | EP_PAGES );
133 + Router::add_rewrite_rules();
317 134 }
318 135
319 136 /**
320 - * Flush rewrite rules;
137 + * Theme compatibility stuff.
321 138 */
322 - public static function flush_rewrite_rules() {
323 - self::add_rewrite_rules();
324 - \flush_rewrite_rules();
139 + public static function theme_compat() {
140 + // We assume that you want to use Post-Formats when enabling the setting.
141 + if ( 'wordpress-post-format' === \get_option( 'activitypub_object_type', ACTIVITYPUB_DEFAULT_OBJECT_TYPE ) ) {
142 + if ( ! get_theme_support( 'post-formats' ) ) {
143 + // Add support for the Aside, Gallery Post Formats...
144 + add_theme_support(
145 + 'post-formats',
146 + array(
147 + 'gallery',
148 + 'status',
149 + 'image',
150 + 'video',
151 + 'audio',
152 + )
153 + );
154 + }
155 + }
325 156 }
326 157
327 158 /**
328 - * Theme compatibility stuff
159 + * Add the 'activitypub' capability to users who can publish posts.
329 160 *
330 - * @return void
161 + * @param int $user_id User ID.
331 162 */
332 - public static function theme_compat() {
333 - $site_icon = get_theme_support( 'custom-logo' );
334 -
335 - if ( ! $site_icon ) {
336 - // custom logo support
337 - add_theme_support(
338 - 'custom-logo',
339 - array(
340 - 'height' => 80,
341 - 'width' => 80,
342 - )
343 - );
163 + public static function user_register( $user_id ) {
164 + if ( \user_can( $user_id, 'publish_posts' ) ) {
165 + $user = \get_user_by( 'id', $user_id );
166 + $user->add_cap( 'activitypub' );
344 167 }
345 -
346 - $custom_header = get_theme_support( 'custom-header' );
347 -
348 - if ( ! $custom_header ) {
349 - // This theme supports a custom header
350 - $custom_header_args = array(
351 - 'width' => 1250,
352 - 'height' => 600,
353 - 'header-text' => true,
354 - );
355 - add_theme_support( 'custom-header', $custom_header_args );
356 - }
357 168 }
358 169
359 170 /**
360 - * Display plugin upgrade notice to users
361 - *
362 - * @param array $data The plugin data
363 - *
364 - * @return void
171 + * Register user meta.
365 172 */
366 - public static function plugin_update_message( $data ) {
367 - if ( ! isset( $data['upgrade_notice'] ) ) {
368 - return;
369 - }
173 + public static function register_user_meta() {
174 + $blog_prefix = $GLOBALS['wpdb']->get_blog_prefix();
370 175
371 - printf(
372 - '<div class="update-message">%s</div>',
373 - wp_kses(
374 - wpautop( $data['upgrade_notice '] ),
375 - array(
376 - 'p' => array(),
377 - 'a' => array( 'href', 'title' ),
378 - 'strong' => array(),
379 - 'em' => array(),
380 - )
176 + \register_meta(
177 + 'user',
178 + $blog_prefix . 'activitypub_also_known_as',
179 + array(
180 + 'type' => 'array',
181 + 'description' => 'An array of URLs that the user is known by.',
182 + 'single' => true,
183 + 'default' => array(),
184 + 'sanitize_callback' => array( Sanitize::class, 'identifier_list' ),
381 185 )
382 186 );
383 - }
384 187
385 - /**
386 - * Register the "Followers" Taxonomy
387 - *
388 - * @return void
389 - */
390 - private static function register_post_types() {
391 - \register_post_type(
392 - Followers::POST_TYPE,
188 + \register_meta(
189 + 'user',
190 + $blog_prefix . 'activitypub_hide_social_graph',
393 191 array(
394 - 'labels' => array(
395 - 'name' => _x( 'Followers', 'post_type plural name', 'activitypub' ),
396 - 'singular_name' => _x( 'Follower', 'post_type single name', 'activitypub' ),
397 - ),
398 - 'public' => false,
399 - 'hierarchical' => false,
400 - 'rewrite' => false,
401 - 'query_var' => false,
402 - 'delete_with_user' => false,
403 - 'can_export' => true,
404 - 'supports' => array(),
192 + 'type' => 'integer',
193 + 'description' => 'Hide Followers and Followings on Profile.',
194 + 'single' => true,
195 + 'default' => 0,
196 + 'sanitize_callback' => 'absint',
197 + 'show_in_rest' => true,
405 198 )
406 199 );
407 200
408 - \register_post_meta(
409 - Followers::POST_TYPE,
410 - 'activitypub_inbox',
201 + \register_meta(
202 + 'user',
203 + $blog_prefix . 'activitypub_old_host_data',
411 204 array(
205 + 'description' => 'Actor object for the user on the old host.',
206 + 'single' => true,
207 + )
208 + );
209 +
210 + \register_meta(
211 + 'user',
212 + $blog_prefix . 'activitypub_moved_to',
213 + array(
412 214 'type' => 'string',
215 + 'description' => 'The new URL of the user.',
413 216 'single' => true,
414 217 'sanitize_callback' => 'sanitize_url',
415 218 )
416 219 );
417 220
418 - \register_post_meta(
419 - Followers::POST_TYPE,
420 - 'activitypub_errors',
221 + \register_meta(
222 + 'user',
223 + $blog_prefix . 'activitypub_description',
421 224 array(
422 225 'type' => 'string',
423 - 'single' => false,
424 - 'sanitize_callback' => function ( $value ) {
425 - if ( ! is_string( $value ) ) {
426 - throw new Exception( 'Error message is no valid string' );
427 - }
226 + 'description' => 'The user description.',
227 + 'single' => true,
228 + 'default' => '',
229 + 'sanitize_callback' => static function ( $value ) {
230 + return wp_kses( $value, 'user_description' );
231 + },
232 + )
233 + );
428 234
429 - return esc_sql( $value );
430 - },
235 + \register_meta(
236 + 'user',
237 + $blog_prefix . 'activitypub_icon',
238 + array(
239 + 'type' => 'integer',
240 + 'description' => 'The attachment ID for user profile image.',
241 + 'single' => true,
242 + 'default' => 0,
243 + 'sanitize_callback' => 'absint',
431 244 )
432 245 );
433 246
434 - \register_post_meta(
435 - Followers::POST_TYPE,
436 - 'activitypub_user_id',
247 + \register_meta(
248 + 'user',
249 + $blog_prefix . 'activitypub_header_image',
437 250 array(
438 - 'type' => 'string',
439 - 'single' => false,
440 - 'sanitize_callback' => function ( $value ) {
441 - return esc_sql( $value );
251 + 'type' => 'integer',
252 + 'description' => 'The attachment ID for the user header image.',
253 + 'single' => true,
254 + 'default' => 0,
255 + 'sanitize_callback' => 'absint',
256 + )
257 + );
258 +
259 + \register_meta(
260 + 'user',
261 + $blog_prefix . 'activitypub_mailer_new_dm',
262 + array(
263 + 'type' => 'integer',
264 + 'description' => 'Send a notification when someone sends this user a direct message.',
265 + 'single' => true,
266 + 'sanitize_callback' => 'absint',
267 + )
268 + );
269 + \add_filter( 'get_user_option_activitypub_mailer_new_dm', array( self::class, 'user_options_default' ) );
270 +
271 + \register_meta(
272 + 'user',
273 + $blog_prefix . 'activitypub_mailer_new_follower',
274 + array(
275 + 'type' => 'integer',
276 + 'description' => 'Send a notification when someone starts to follow this user.',
277 + 'single' => true,
278 + 'sanitize_callback' => 'absint',
279 + )
280 + );
281 + \add_filter( 'get_user_option_activitypub_mailer_new_follower', array( self::class, 'user_options_default' ) );
282 +
283 + \register_meta(
284 + 'user',
285 + $blog_prefix . 'activitypub_mailer_new_mention',
286 + array(
287 + 'type' => 'integer',
288 + 'description' => 'Send a notification when someone mentions this user.',
289 + 'single' => true,
290 + 'sanitize_callback' => 'absint',
291 + )
292 + );
293 + \add_filter( 'get_user_option_activitypub_mailer_new_mention', array( self::class, 'user_options_default' ) );
294 +
295 + \register_meta(
296 + 'user',
297 + 'activitypub_show_welcome_tab',
298 + array(
299 + 'type' => 'integer',
300 + 'description' => 'Whether to show the welcome tab.',
301 + 'single' => true,
302 + 'default' => 1,
303 + 'sanitize_callback' => 'absint',
304 + )
305 + );
306 +
307 + \register_meta(
308 + 'user',
309 + 'activitypub_show_advanced_tab',
310 + array(
311 + 'type' => 'integer',
312 + 'description' => 'Whether to show the advanced tab.',
313 + 'single' => true,
314 + 'default' => 0,
315 + 'sanitize_callback' => 'absint',
316 + )
317 + );
318 +
319 + // Moderation user meta.
320 + \register_meta(
321 + 'user',
322 + 'activitypub_blocked_actors',
323 + array(
324 + 'type' => 'array',
325 + 'description' => 'User-specific blocked ActivityPub actors.',
326 + 'single' => true,
327 + 'default' => array(),
328 + 'sanitize_callback' => array( Sanitize::class, 'identifier_list' ),
329 + )
330 + );
331 +
332 + \register_meta(
333 + 'user',
334 + 'activitypub_blocked_domains',
335 + array(
336 + 'type' => 'array',
337 + 'description' => 'User-specific blocked ActivityPub domains.',
338 + 'single' => true,
339 + 'default' => array(),
340 + 'sanitize_callback' => static function ( $value ) {
341 + return \array_unique( \array_map( array( Sanitize::class, 'host_list' ), $value ) );
442 342 },
443 343 )
444 344 );
445 345
446 - \register_post_meta(
447 - Followers::POST_TYPE,
448 - 'activitypub_actor_json',
346 + \register_meta(
347 + 'user',
348 + 'activitypub_blocked_keywords',
449 349 array(
450 - 'type' => 'string',
350 + 'type' => 'array',
351 + 'description' => 'User-specific blocked ActivityPub keywords.',
451 352 'single' => true,
452 - 'sanitize_callback' => function ( $value ) {
453 - return sanitize_text_field( $value );
353 + 'default' => array(),
354 + 'sanitize_callback' => static function ( $value ) {
355 + return \array_map( 'sanitize_text_field', $value );
454 356 },
455 357 )
456 358 );
457 -
458 - \do_action( 'activitypub_after_register_post_type' );
459 359 }
460 360
461 361 /**
462 - * Filters the CSS classes to add an ActivityPub class.
362 + * Set default values for user options.
463 363 *
464 - * @param string[] $classes An array of comment classes.
465 - * @param string[] $css_class An array of additional classes added to the list.
466 - * @param string $comment_id The comment ID as a numeric string.
467 - *
468 - * @return string[] An array of classes.
364 + * @param bool|string $value Option value.
365 + * @return bool|string
469 366 */
470 - public static function comment_class( $classes, $css_class, $comment_id ) {
471 - // check if ActivityPub comment
472 - if ( 'activitypub' === get_comment_meta( $comment_id, 'protocol', true ) ) {
473 - $classes[] = 'activitypub-comment';
367 + public static function user_options_default( $value ) {
368 + if ( false === $value ) {
369 + return '1';
474 370 }
475 371
476 - return $classes;
372 + return $value;
477 373 }
478 374 }