Skip to content

Commit 214acc5

Browse files
authored
Centralize settings registration in Options class (#2630)
1 parent 1b0ace9 commit 214acc5

File tree

4 files changed

+370
-363
lines changed

4 files changed

+370
-363
lines changed

includes/class-options.php

Lines changed: 366 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
namespace Activitypub;
99

10+
use Activitypub\Model\Blog;
11+
1012
/**
1113
* Options class.
1214
*/
@@ -16,6 +18,9 @@ class Options {
1618
* Initialize the options.
1719
*/
1820
public static function init() {
21+
\add_action( 'admin_init', array( self::class, 'register_settings' ) );
22+
\add_action( 'rest_api_init', array( self::class, 'register_settings' ) );
23+
1924
\add_filter( 'pre_option_activitypub_actor_mode', array( self::class, 'pre_option_activitypub_actor_mode' ) );
2025
\add_filter( 'pre_option_activitypub_authorized_fetch', array( self::class, 'pre_option_activitypub_authorized_fetch' ) );
2126
\add_filter( 'pre_option_activitypub_vary_header', array( self::class, 'pre_option_activitypub_vary_header' ) );
@@ -31,6 +36,367 @@ public static function init() {
3136
\add_action( 'update_option_activitypub_relay_mode', array( self::class, 'relay_mode_changed' ), 10, 2 );
3237
}
3338

39+
/**
40+
* Register ActivityPub settings.
41+
*/
42+
public static function register_settings() {
43+
/*
44+
* Options Group: activitypub
45+
*/
46+
\register_setting(
47+
'activitypub',
48+
'activitypub_post_content_type',
49+
array(
50+
'type' => 'string',
51+
'description' => 'Use title and link, summary, full or custom content',
52+
'show_in_rest' => array(
53+
'schema' => array(
54+
'enum' => array( 'title', 'excerpt', 'content' ),
55+
),
56+
),
57+
'default' => 'content',
58+
)
59+
);
60+
61+
\register_setting(
62+
'activitypub',
63+
'activitypub_custom_post_content',
64+
array(
65+
'type' => 'string',
66+
'description' => 'Define your own custom post template',
67+
'show_in_rest' => true,
68+
'default' => ACTIVITYPUB_CUSTOM_POST_CONTENT,
69+
)
70+
);
71+
72+
\register_setting(
73+
'activitypub',
74+
'activitypub_max_image_attachments',
75+
array(
76+
'type' => 'integer',
77+
'description' => 'Number of images to attach to posts.',
78+
'default' => ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS,
79+
'sanitize_callback' => function ( $value ) {
80+
return \is_numeric( $value ) ? \absint( $value ) : ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS;
81+
},
82+
)
83+
);
84+
85+
\register_setting(
86+
'activitypub',
87+
'activitypub_use_hashtags',
88+
array(
89+
'type' => 'boolean',
90+
'description' => 'Add hashtags in the content as native tags and replace the #tag with the tag-link',
91+
'default' => '0',
92+
)
93+
);
94+
95+
\register_setting(
96+
'activitypub',
97+
'activitypub_use_opengraph',
98+
array(
99+
'type' => 'boolean',
100+
'description' => 'Automatically add "fediverse:creator" OpenGraph tags for Authors and the Blog-User.',
101+
'default' => '1',
102+
)
103+
);
104+
105+
\register_setting(
106+
'activitypub',
107+
'activitypub_support_post_types',
108+
array(
109+
'type' => 'string',
110+
'description' => 'Enable ActivityPub support for post types',
111+
'show_in_rest' => true,
112+
'default' => array( 'post' ),
113+
)
114+
);
115+
116+
\register_setting(
117+
'activitypub',
118+
'activitypub_actor_mode',
119+
array(
120+
'type' => 'integer',
121+
'description' => 'Choose your preferred Actor-Mode.',
122+
'default' => ACTIVITYPUB_ACTOR_MODE,
123+
)
124+
);
125+
126+
\register_setting(
127+
'activitypub',
128+
'activitypub_attribution_domains',
129+
array(
130+
'type' => 'string',
131+
'description' => 'Websites allowed to credit you.',
132+
'default' => home_host(),
133+
'sanitize_callback' => array( Sanitize::class, 'host_list' ),
134+
)
135+
);
136+
137+
\register_setting(
138+
'activitypub',
139+
'activitypub_allow_likes',
140+
array(
141+
'type' => 'integer',
142+
'description' => 'Allow likes.',
143+
'default' => '1',
144+
'sanitize_callback' => 'absint',
145+
)
146+
);
147+
148+
\register_setting(
149+
'activitypub',
150+
'activitypub_allow_reposts',
151+
array(
152+
'type' => 'integer',
153+
'description' => 'Allow reposts.',
154+
'default' => '1',
155+
'sanitize_callback' => 'absint',
156+
)
157+
);
158+
159+
\register_setting(
160+
'activitypub',
161+
'activitypub_auto_approve_reactions',
162+
array(
163+
'type' => 'integer',
164+
'description' => 'Auto approve Reactions.',
165+
'default' => '0',
166+
'sanitize_callback' => 'absint',
167+
)
168+
);
169+
170+
\register_setting(
171+
'activitypub',
172+
'activitypub_relays',
173+
array(
174+
'type' => 'array',
175+
'description' => 'Relays',
176+
'default' => array(),
177+
'sanitize_callback' => array( Sanitize::class, 'url_list' ),
178+
)
179+
);
180+
181+
\register_setting(
182+
'activitypub',
183+
'activitypub_site_blocked_actors',
184+
array(
185+
'type' => 'array',
186+
'description' => 'Site-wide blocked ActivityPub actors.',
187+
'default' => array(),
188+
'sanitize_callback' => array( Sanitize::class, 'identifier_list' ),
189+
)
190+
);
191+
192+
/*
193+
* Options Group: activitypub_advanced
194+
*/
195+
\register_setting(
196+
'activitypub_advanced',
197+
'activitypub_outbox_purge_days',
198+
array(
199+
'type' => 'integer',
200+
'description' => 'Number of days to keep items in the Outbox.',
201+
'default' => 180,
202+
)
203+
);
204+
205+
\register_setting(
206+
'activitypub_advanced',
207+
'activitypub_inbox_purge_days',
208+
array(
209+
'type' => 'integer',
210+
'description' => 'Number of days to keep items in the Inbox.',
211+
'default' => 180,
212+
)
213+
);
214+
215+
\register_setting(
216+
'activitypub_advanced',
217+
'activitypub_ap_post_purge_days',
218+
array(
219+
'type' => 'integer',
220+
'description' => 'Number of days to keep remote posts.',
221+
'default' => 30,
222+
)
223+
);
224+
225+
\register_setting(
226+
'activitypub_advanced',
227+
'activitypub_vary_header',
228+
array(
229+
'type' => 'boolean',
230+
'description' => 'Add the Vary header to the ActivityPub response.',
231+
'default' => true,
232+
)
233+
);
234+
235+
\register_setting(
236+
'activitypub_advanced',
237+
'activitypub_content_negotiation',
238+
array(
239+
'type' => 'boolean',
240+
'description' => 'Enable content negotiation.',
241+
'default' => true,
242+
)
243+
);
244+
245+
\register_setting(
246+
'activitypub_advanced',
247+
'activitypub_authorized_fetch',
248+
array(
249+
'type' => 'boolean',
250+
'description' => 'Require HTTP signature authentication.',
251+
'default' => false,
252+
)
253+
);
254+
255+
\register_setting(
256+
'activitypub_advanced',
257+
'activitypub_rfc9421_signature',
258+
array(
259+
'type' => 'boolean',
260+
'description' => 'Use RFC-9421 signature.',
261+
'default' => false,
262+
)
263+
);
264+
265+
\register_setting(
266+
'activitypub_advanced',
267+
'activitypub_following_ui',
268+
array(
269+
'type' => 'boolean',
270+
'description' => 'Show Following UI in admin menus and settings.',
271+
'default' => false,
272+
)
273+
);
274+
275+
\register_setting(
276+
'activitypub_advanced',
277+
'activitypub_create_posts',
278+
array(
279+
'type' => 'boolean',
280+
'description' => 'Allow creating posts via ActivityPub.',
281+
'default' => false,
282+
)
283+
);
284+
285+
\register_setting(
286+
'activitypub_advanced',
287+
'activitypub_object_type',
288+
array(
289+
'type' => 'string',
290+
'description' => 'The Activity-Object-Type',
291+
'show_in_rest' => array(
292+
'schema' => array(
293+
'enum' => array( 'note', 'wordpress-post-format' ),
294+
),
295+
),
296+
'default' => ACTIVITYPUB_DEFAULT_OBJECT_TYPE,
297+
)
298+
);
299+
300+
\register_setting(
301+
'activitypub_advanced',
302+
'activitypub_relay_mode',
303+
array(
304+
'type' => 'integer',
305+
'description' => 'Enable relay mode to forward public activities to all followers.',
306+
'default' => 0,
307+
'sanitize_callback' => 'absint',
308+
)
309+
);
310+
311+
/*
312+
* Options Group: activitypub_blog
313+
*/
314+
\register_setting(
315+
'activitypub_blog',
316+
'activitypub_blog_description',
317+
array(
318+
'type' => 'string',
319+
'description' => 'The Description of the Blog-User',
320+
'show_in_rest' => true,
321+
'default' => '',
322+
)
323+
);
324+
325+
\register_setting(
326+
'activitypub_blog',
327+
'activitypub_blog_identifier',
328+
array(
329+
'type' => 'string',
330+
'description' => 'The Identifier of the Blog-User',
331+
'show_in_rest' => true,
332+
'default' => Blog::get_default_username(),
333+
'sanitize_callback' => array( Sanitize::class, 'blog_identifier' ),
334+
)
335+
);
336+
337+
\register_setting(
338+
'activitypub_blog',
339+
'activitypub_header_image',
340+
array(
341+
'type' => 'integer',
342+
'description' => 'The Attachment-ID of the Sites Header-Image',
343+
'default' => null,
344+
)
345+
);
346+
347+
\register_setting(
348+
'activitypub_blog',
349+
'activitypub_blog_user_mailer_new_dm',
350+
array(
351+
'type' => 'integer',
352+
'description' => 'Send a notification when someone sends a user of the blog a direct message.',
353+
'default' => 1,
354+
)
355+
);
356+
357+
\register_setting(
358+
'activitypub_blog',
359+
'activitypub_blog_user_mailer_new_follower',
360+
array(
361+
'type' => 'integer',
362+
'description' => 'Send a notification when someone starts to follow a user of the blog.',
363+
'default' => 1,
364+
)
365+
);
366+
367+
\register_setting(
368+
'activitypub_blog',
369+
'activitypub_blog_user_mailer_new_mention',
370+
array(
371+
'type' => 'integer',
372+
'description' => 'Send a notification when someone mentions a user of the blog.',
373+
'default' => 1,
374+
)
375+
);
376+
377+
\register_setting(
378+
'activitypub_blog',
379+
'activitypub_blog_user_also_known_as',
380+
array(
381+
'type' => 'array',
382+
'description' => 'An array of URLs that the blog user is known by.',
383+
'default' => array(),
384+
'sanitize_callback' => array( Sanitize::class, 'identifier_list' ),
385+
)
386+
);
387+
388+
\register_setting(
389+
'activitypub_blog',
390+
'activitypub_hide_social_graph',
391+
array(
392+
'type' => 'integer',
393+
'description' => 'Hide Followers and Followings on Profile.',
394+
'default' => 0,
395+
'sanitize_callback' => 'absint',
396+
)
397+
);
398+
}
399+
34400
/**
35401
* Delete all options.
36402
*/

0 commit comments

Comments
 (0)