PluginProbe
ActivityPub / 7.0.0
ActivityPub v7.0.0
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
activitypub / includes / wp-admin / class-settings-fields.php

class-settings-fields.php in ActivityPub 7.0.0, at includes/wp-admin/class-settings-fields.php

462 lines 16.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * ActivityPub Settings Fields Class.
4 *
5 * @package Activitypub
6 */
7
8 namespace Activitypub\WP_Admin;
9
10 use function Activitypub\home_host;
11 use function Activitypub\site_supports_blocks;
12
13 /**
14 * Class Settings_Fields.
15 */
16 class Settings_Fields {
17 /**
18 * Initialize the settings fields.
19 */
20 public static function init() {
21 add_action( 'load-settings_page_activitypub', array( self::class, 'register_settings_fields' ) );
22 }
23
24 /**
25 * Register settings fields.
26 */
27 public static function register_settings_fields() {
28 // Add settings sections.
29 add_settings_section(
30 'activitypub_profiles',
31 __( 'Profiles', 'activitypub' ),
32 '__return_empty_string',
33 'activitypub_settings'
34 );
35
36 add_settings_section(
37 'activitypub_activities',
38 __( 'Activities', 'activitypub' ),
39 '__return_empty_string',
40 'activitypub_settings'
41 );
42
43 add_settings_section(
44 'activitypub_general',
45 __( 'General', 'activitypub' ),
46 '__return_empty_string',
47 'activitypub_settings'
48 );
49
50 add_settings_section(
51 'activitypub_server',
52 __( 'Server', 'activitypub' ),
53 '__return_empty_string',
54 'activitypub_settings'
55 );
56
57 // Add settings fields.
58 add_settings_field(
59 'activitypub_actor_mode',
60 __( 'Enable profiles by type', 'activitypub' ),
61 array( self::class, 'render_actor_mode_field' ),
62 'activitypub_settings',
63 'activitypub_profiles'
64 );
65
66 add_settings_field(
67 'activitypub_object_type',
68 __( 'Activity-Object-Type', 'activitypub' ),
69 array( self::class, 'render_object_type_field' ),
70 'activitypub_settings',
71 'activitypub_activities'
72 );
73
74 $object_type = \get_option( 'activitypub_object_type', ACTIVITYPUB_DEFAULT_OBJECT_TYPE );
75 if ( 'note' === $object_type ) {
76 add_settings_field(
77 'activitypub_custom_post_content',
78 __( 'Post content', 'activitypub' ),
79 array( self::class, 'render_custom_post_content_field' ),
80 'activitypub_settings',
81 'activitypub_activities',
82 array( 'label_for' => 'activitypub_custom_post_content' )
83 );
84 }
85
86 add_settings_field(
87 'activitypub_max_image_attachments',
88 __( 'Media attachments', 'activitypub' ),
89 array( self::class, 'render_max_image_attachments_field' ),
90 'activitypub_settings',
91 'activitypub_activities',
92 array( 'label_for' => 'activitypub_max_image_attachments' )
93 );
94
95 add_settings_field(
96 'activitypub_support_post_types',
97 __( 'Supported post types', 'activitypub' ),
98 array( self::class, 'render_support_post_types_field' ),
99 'activitypub_settings',
100 'activitypub_activities'
101 );
102
103 add_settings_field(
104 'activitypub_allow_interactions',
105 __( 'Post interactions', 'activitypub' ),
106 array( self::class, 'render_allow_interactions_field' ),
107 'activitypub_settings',
108 'activitypub_activities'
109 );
110
111 add_settings_field(
112 'activitypub_use_hashtags',
113 __( 'Hashtags', 'activitypub' ),
114 array( self::class, 'render_use_hashtags_field' ),
115 'activitypub_settings',
116 'activitypub_activities',
117 array( 'label_for' => 'activitypub_use_hashtags' )
118 );
119
120 add_settings_field(
121 'activitypub_use_opengraph',
122 __( 'OpenGraph', 'activitypub' ),
123 array( self::class, 'render_use_opengraph_field' ),
124 'activitypub_settings',
125 'activitypub_general',
126 array( 'label_for' => 'activitypub_use_opengraph' )
127 );
128
129 add_settings_field(
130 'activitypub_attribution_domains',
131 __( 'Attribution Domains', 'activitypub' ),
132 array( self::class, 'render_attribution_domains_field' ),
133 'activitypub_settings',
134 'activitypub_general',
135 array( 'label_for' => 'activitypub_attribution_domains' )
136 );
137
138 add_settings_field(
139 'activitypub_blocklist',
140 __( 'Blocklist', 'activitypub' ),
141 array( self::class, 'render_blocklist_field' ),
142 'activitypub_settings',
143 'activitypub_server'
144 );
145
146 add_settings_field(
147 'activitypub_relays',
148 __( 'Relays', 'activitypub' ),
149 array( self::class, 'render_relays_field' ),
150 'activitypub_settings',
151 'activitypub_server',
152 array( 'label_for' => 'activitypub_relays' )
153 );
154 }
155
156 /**
157 * Render actor mode field.
158 */
159 public static function render_actor_mode_field() {
160 $disabled = ( \defined( 'ACTIVITYPUB_SINGLE_USER_MODE' ) && ACTIVITYPUB_SINGLE_USER_MODE ) ||
161 ( \defined( 'ACTIVITYPUB_DISABLE_USER' ) && ACTIVITYPUB_DISABLE_USER ) ||
162 ( \defined( 'ACTIVITYPUB_DISABLE_BLOG_USER' ) && ACTIVITYPUB_DISABLE_BLOG_USER );
163
164 if ( $disabled ) :
165 ?>
166 <p class="description">
167 <?php esc_html_e( 'âš  This setting is defined through server configuration by your blog&#8217;s administrator.', 'activitypub' ); ?>
168 </p>
169 <?php
170 return;
171 endif;
172
173 $value = get_option( 'activitypub_actor_mode', ACTIVITYPUB_ACTOR_MODE );
174 ?>
175 <fieldset class="actor-mode-selection">
176 <div class="row">
177 <input type="radio" id="actor-mode" name="activitypub_actor_mode" value="<?php echo esc_attr( ACTIVITYPUB_ACTOR_MODE ); ?>" <?php checked( ACTIVITYPUB_ACTOR_MODE, $value ); ?> />
178 <div>
179 <label for="actor-mode"><strong><?php esc_html_e( 'Author Profiles Only', 'activitypub' ); ?></strong></label>
180 <p class="description">
181 <?php echo wp_kses( __( 'Every author on this blog (with the <code>activitypub</code> capability) gets their own ActivityPub profile.', 'activitypub' ), array( 'code' => array() ) ); ?>
182 <strong>
183 <?php
184 echo wp_kses(
185 sprintf(
186 // translators: %s is a URL.
187 __( 'You can add/remove the capability in the <a href="%s">user settings.</a>', 'activitypub' ),
188 admin_url( '/users.php' )
189 ),
190 array( 'a' => array( 'href' => array() ) )
191 );
192 ?>
193 </strong>
194 <?php echo wp_kses( __( 'Select all the users you want to update, choose the method from the drop-down list and click on the "Apply" button.', 'activitypub' ), array( 'code' => array() ) ); ?>
195 </p>
196 </div>
197 </div>
198 <div class="row">
199 <input type="radio" id="blog-mode" name="activitypub_actor_mode" value="<?php echo esc_attr( ACTIVITYPUB_BLOG_MODE ); ?>" <?php checked( ACTIVITYPUB_BLOG_MODE, $value ); ?> />
200 <div>
201 <label for="blog-mode"><strong><?php esc_html_e( 'Blog profile only', 'activitypub' ); ?></strong></label>
202 <p class="description">
203 <?php esc_html_e( 'Your blog becomes a single ActivityPub profile and every post will be published under this profile instead of the individual author profiles.', 'activitypub' ); ?>
204 </p>
205 </div>
206 </div>
207 <div class="row">
208 <input type="radio" id="actor-blog-mode" name="activitypub_actor_mode" value="<?php echo esc_attr( ACTIVITYPUB_ACTOR_AND_BLOG_MODE ); ?>" <?php checked( ACTIVITYPUB_ACTOR_AND_BLOG_MODE, $value ); ?> />
209 <div>
210 <label for="actor-blog-mode"><strong><?php esc_html_e( 'Both author and blog profiles', 'activitypub' ); ?></strong></label>
211 <p class="description">
212 <?php esc_html_e( "This combines both modes. Users can be followed individually, while following the blog will show boosts of individual user's posts.", 'activitypub' ); ?>
213 </p>
214 </div>
215 </div>
216 </fieldset>
217 <?php
218 }
219
220 /**
221 * Render object type field.
222 */
223 public static function render_object_type_field() {
224 $value = get_option( 'activitypub_object_type', ACTIVITYPUB_DEFAULT_OBJECT_TYPE );
225 ?>
226 <p>
227 <label>
228 <input type="radio" name="activitypub_object_type" value="wordpress-post-format" <?php checked( 'wordpress-post-format', $value ); ?> />
229 <?php esc_html_e( 'Automatic (default)', 'activitypub' ); ?>
230 -
231 <span class="description">
232 <?php esc_html_e( 'Let the plugin choose the best possible format for you.', 'activitypub' ); ?>
233 </span>
234 </label>
235 </p>
236 <p>
237 <label>
238 <input type="radio" name="activitypub_object_type" value="note" <?php checked( 'note', $value ); ?> />
239 <?php esc_html_e( 'Note', 'activitypub' ); ?>
240 -
241 <span class="description">
242 <?php esc_html_e( 'Should work with most platforms.', 'activitypub' ); ?>
243 </span>
244 </label>
245 </p>
246 <?php
247 }
248
249 /**
250 * Render custom post content field.
251 */
252 public static function render_custom_post_content_field() {
253 $value = get_option( 'activitypub_custom_post_content', ACTIVITYPUB_CUSTOM_POST_CONTENT );
254 ?>
255 <p><strong><?php esc_html_e( 'These settings only apply if you use the "Note" Object-Type setting above.', 'activitypub' ); ?></strong></p>
256 <p>
257 <textarea id="activitypub_custom_post_content" name="activitypub_custom_post_content" rows="10" cols="50" class="large-text" placeholder="<?php echo esc_attr( ACTIVITYPUB_CUSTOM_POST_CONTENT ); ?>"><?php echo esc_textarea( wp_kses( $value, 'post' ) ); ?></textarea>
258 <details>
259 <summary><?php esc_html_e( 'See a list of ActivityPub Template Tags.', 'activitypub' ); ?></summary>
260 <div class="description">
261 <ul>
262 <li><code>[ap_title]</code> - <?php esc_html_e( 'The post&#8217;s title.', 'activitypub' ); ?></li>
263 <li><code>[ap_content]</code> - <?php esc_html_e( 'The post&#8217;s content.', 'activitypub' ); ?></li>
264 <li><code>[ap_excerpt]</code> - <?php esc_html_e( 'The post&#8217;s excerpt (may be truncated).', 'activitypub' ); ?></li>
265 <li><code>[ap_permalink]</code> - <?php esc_html_e( 'The post&#8217;s permalink.', 'activitypub' ); ?></li>
266 <li><code>[ap_shortlink]</code> - <?php echo wp_kses( __( 'The post&#8217;s shortlink. I can recommend <a href="https://wordpress.org/plugins/hum/" target="_blank">Hum</a>.', 'activitypub' ), 'default' ); ?></li>
267 <li><code>[ap_hashtags]</code> - <?php esc_html_e( 'The post&#8217;s tags as hashtags.', 'activitypub' ); ?></li>
268 </ul>
269 <p><?php esc_html_e( 'You can find the full list with all possible attributes in the help section on the top-right of the screen.', 'activitypub' ); ?></p>
270 </div>
271 </details>
272 </p>
273 <?php
274 }
275
276 /**
277 * Render max image attachments field.
278 */
279 public static function render_max_image_attachments_field() {
280 $value = get_option( 'activitypub_max_image_attachments', ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS );
281 ?>
282 <input id="activitypub_max_image_attachments" value="<?php echo esc_attr( $value ); ?>" name="activitypub_max_image_attachments" type="number" min="0" max="10" class="small-text" />
283 <p class="description">
284 <?php
285 echo wp_kses(
286 sprintf(
287 // translators: %s is a number.
288 __( 'The number of media (images, audio, video) to attach to posts. Default: <code>%s</code>', 'activitypub' ),
289 esc_html( ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS )
290 ),
291 'default'
292 );
293 ?>
294 </p>
295 <p class="description">
296 <em>
297 <?php esc_html_e( 'Note: audio and video attachments are only supported from Block Editor.', 'activitypub' ); ?>
298 </em>
299 </p>
300 <?php
301 }
302
303 /**
304 * Render support post types field.
305 */
306 public static function render_support_post_types_field() {
307 $post_types = get_post_types( array( 'public' => true ), 'objects' );
308 $supported_post_types = (array) get_option( 'activitypub_support_post_types', array( 'post' ) );
309 ?>
310 <fieldset>
311 <?php esc_html_e( 'Automatically publish items of the selected post types to the fediverse:', 'activitypub' ); ?>
312 <ul>
313 <?php foreach ( $post_types as $post_type ) : ?>
314 <li>
315 <input type="checkbox" id="activitypub_support_post_type_<?php echo esc_attr( $post_type->name ); ?>" name="activitypub_support_post_types[]" value="<?php echo esc_attr( $post_type->name ); ?>" <?php checked( in_array( $post_type->name, $supported_post_types, true ) ); ?> />
316 <label for="activitypub_support_post_type_<?php echo esc_attr( $post_type->name ); ?>"><?php echo esc_html( $post_type->label ); ?></label>
317 <span class="description">
318 <?php echo esc_html( \Activitypub\get_post_type_description( $post_type ) ); ?>
319 </span>
320 </li>
321 <?php endforeach; ?>
322 </ul>
323 </fieldset>
324 <?php
325 }
326
327 /**
328 * Render allow interactions field.
329 */
330 public static function render_allow_interactions_field() {
331 if ( defined( 'ACTIVITYPUB_DISABLE_INCOMING_INTERACTIONS' ) && ACTIVITYPUB_DISABLE_INCOMING_INTERACTIONS ) {
332 echo '<p class="description">' . \esc_html__( 'âš  This setting is defined through server configuration by your blog&#8217;s administrator.', 'activitypub' ) . '</p>';
333 return;
334 }
335
336 $allow_likes = get_option( 'activitypub_allow_likes', '1' );
337 $allow_reposts = get_option( 'activitypub_allow_reposts', '1' );
338 $auto_approve = get_option( 'activitypub_auto_approve_reactions', '0' );
339 ?>
340 <fieldset>
341 <p>
342 <label>
343 <input type="checkbox" name="activitypub_allow_likes" value="1" <?php checked( '1', $allow_likes ); ?> />
344 <?php esc_html_e( 'Receive likes', 'activitypub' ); ?>
345 </label>
346 </p>
347 <p>
348 <label>
349 <input type="checkbox" name="activitypub_allow_reposts" value="1" <?php checked( '1', $allow_reposts ); ?> />
350 <?php esc_html_e( 'Receive reblogs (boosts)', 'activitypub' ); ?>
351 </label>
352 </p>
353 <p class="interactions description"><?php esc_html_e( 'Types of interactions from the Fediverse your blog should accept.', 'activitypub' ); ?></p>
354 <p>
355 <label>
356 <input type="checkbox" name="activitypub_auto_approve_reactions" value="1" <?php checked( '1', $auto_approve ); ?> />
357 <?php esc_html_e( 'Auto approve reactions', 'activitypub' ); ?>
358 </label>
359 </p>
360 </fieldset>
361 <?php
362 }
363
364 /**
365 * Render use hashtags field.
366 */
367 public static function render_use_hashtags_field() {
368 $value = get_option( 'activitypub_use_hashtags', '1' );
369 ?>
370 <p>
371 <label>
372 <input type="checkbox" id="activitypub_use_hashtags" name="activitypub_use_hashtags" value="1" <?php checked( '1', $value ); ?> />
373 <?php echo wp_kses( __( 'Add hashtags in the content as native tags and replace the <code>#tag</code> with the tag link.', 'activitypub' ), 'default' ); ?>
374 </label>
375 </p>
376 <?php
377 }
378
379 /**
380 * Render use OpenGraph field.
381 */
382 public static function render_use_opengraph_field() {
383 $value = get_option( 'activitypub_use_opengraph', '1' );
384 ?>
385 <p>
386 <label>
387 <input type="checkbox" id="activitypub_use_opengraph" name="activitypub_use_opengraph" value="1" <?php checked( '1', $value ); ?> />
388 <?php echo wp_kses( __( 'Automatically add <code>&lt;meta name="fediverse:creator" /&gt;</code> tags for Authors and the Blog-User. You can read more about the feature on the <a href="https://blog.joinmastodon.org/2024/07/highlighting-journalism-on-mastodon/" target="_blank">Mastodon Blog</a>.', 'activitypub' ), 'post' ); ?>
389 </label>
390 </p>
391 <?php
392 }
393
394 /**
395 * Render attribution domains field.
396 */
397 public static function render_attribution_domains_field() {
398 $value = get_option( 'activitypub_attribution_domains', home_host() );
399 ?>
400 <textarea
401 id="activitypub_attribution_domains"
402 name="activitypub_attribution_domains"
403 class="large-text"
404 cols="50" rows="5"
405 placeholder="<?php echo esc_attr( home_host() ); ?>"
406 ><?php echo esc_textarea( $value ); ?></textarea>
407 <p class="description"><?php esc_html_e( 'Websites allowed to credit you, one per line. Protects from false attributions.', 'activitypub' ); ?></p>
408 <?php
409 }
410
411 /**
412 * Render relays field.
413 */
414 public static function render_relays_field() {
415 $value = \get_option( 'activitypub_relays', array() );
416 ?>
417 <textarea
418 id="activitypub_relays"
419 name="activitypub_relays"
420 class="large-text"
421 cols="50"
422 rows="5"
423 ><?php echo \esc_textarea( implode( PHP_EOL, $value ) ); ?></textarea>
424 <p class="description">
425 <?php echo \wp_kses( \__( 'A <strong>Fediverse-Relay</strong> distributes content across instances, expanding reach, engagement, and discoverability, especially for smaller instances.', 'activitypub' ), 'default' ); ?>
426 </p>
427 <p class="description">
428 <?php
429 echo \wp_kses(
430 \__( 'Enter the <strong>Inbox-URLs</strong> (e.g. <code>https://relay.example.com/inbox</code>) of the relays you want to use, one per line.', 'activitypub' ),
431 array(
432 'strong' => array(),
433 'code' => array(),
434 )
435 );
436 ?>
437 <?php echo \wp_kses( \__( 'You can find a list of public relays on <a href="https://relaylist.com/" target="_blank">relaylist.com</a> or on <a href="https://fedidb.org/software/activity-relay" target="_blank">FediDB</a>.', 'activitypub' ), 'default' ); ?>
438 </p>
439 <?php
440 }
441
442 /**
443 * Render blocklist field.
444 */
445 public static function render_blocklist_field() {
446 ?>
447 <p>
448 <?php
449 echo \wp_kses(
450 \sprintf(
451 // translators: %s is a URL.
452 \__( 'To block servers, add the host of the server to the "<a href="%s">Disallowed Comment Keys</a>" list.', 'activitypub' ),
453 \esc_url( \admin_url( 'options-discussion.php#disallowed_keys' ) )
454 ),
455 'default'
456 );
457 ?>
458 </p>
459 <?php
460 }
461 }
462