PluginProbe
ActivityPub / 7.7.0
ActivityPub v7.7.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.7.0, at includes/wp-admin/class-settings-fields.php

495 lines 18.1 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 Activitypub\Moderation;
11
12 use function Activitypub\home_host;
13
14 /**
15 * Class Settings_Fields.
16 */
17 class Settings_Fields {
18 /**
19 * Initialize the settings fields.
20 */
21 public static function init() {
22 add_action( 'load-settings_page_activitypub', array( self::class, 'register_settings_fields' ) );
23 }
24
25 /**
26 * Register settings fields.
27 */
28 public static function register_settings_fields() {
29 // Add settings sections.
30 add_settings_section(
31 'activitypub_profiles',
32 __( 'Profiles', 'activitypub' ),
33 '__return_empty_string',
34 'activitypub_settings'
35 );
36
37 add_settings_section(
38 'activitypub_activities',
39 __( 'Activities', 'activitypub' ),
40 '__return_empty_string',
41 'activitypub_settings'
42 );
43
44 add_settings_section(
45 'activitypub_general',
46 __( 'General', 'activitypub' ),
47 '__return_empty_string',
48 'activitypub_settings'
49 );
50
51 add_settings_section(
52 'activitypub_server',
53 __( 'Server', 'activitypub' ),
54 '__return_empty_string',
55 'activitypub_settings'
56 );
57
58 add_settings_section(
59 'activitypub_moderation',
60 \esc_html__( 'Moderation', 'activitypub' ),
61 array( self::class, 'render_moderation_section_description' ),
62 'activitypub_settings'
63 );
64
65 // Add settings fields.
66 add_settings_field(
67 'activitypub_actor_mode',
68 __( 'Enable profiles by type', 'activitypub' ),
69 array( self::class, 'render_actor_mode_field' ),
70 'activitypub_settings',
71 'activitypub_profiles'
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_relays',
140 __( 'Relays', 'activitypub' ),
141 array( self::class, 'render_relays_field' ),
142 'activitypub_settings',
143 'activitypub_server',
144 array( 'label_for' => 'activitypub_relays' )
145 );
146
147 add_settings_field(
148 'activitypub_site_blocked_domains',
149 \esc_html__( 'Blocked Domains', 'activitypub' ),
150 array( self::class, 'render_site_blocked_domains_field' ),
151 'activitypub_settings',
152 'activitypub_moderation'
153 );
154
155 add_settings_field(
156 'activitypub_site_blocked_keywords',
157 \esc_html__( 'Blocked Keywords', 'activitypub' ),
158 array( self::class, 'render_site_blocked_keywords_field' ),
159 'activitypub_settings',
160 'activitypub_moderation'
161 );
162 }
163
164 /**
165 * Render actor mode field.
166 */
167 public static function render_actor_mode_field() {
168 $disabled = ( \defined( 'ACTIVITYPUB_SINGLE_USER_MODE' ) && ACTIVITYPUB_SINGLE_USER_MODE ) ||
169 ( \defined( 'ACTIVITYPUB_DISABLE_USER' ) && ACTIVITYPUB_DISABLE_USER ) ||
170 ( \defined( 'ACTIVITYPUB_DISABLE_BLOG_USER' ) && ACTIVITYPUB_DISABLE_BLOG_USER );
171
172 if ( $disabled ) :
173 ?>
174 <p class="description">
175 <?php esc_html_e( 'âš  This setting is defined through server configuration by your blog&#8217;s administrator.', 'activitypub' ); ?>
176 </p>
177 <?php
178 return;
179 endif;
180
181 $value = get_option( 'activitypub_actor_mode', ACTIVITYPUB_ACTOR_MODE );
182 ?>
183 <fieldset class="actor-mode-selection">
184 <div class="row">
185 <input type="radio" id="actor-mode" name="activitypub_actor_mode" value="<?php echo esc_attr( ACTIVITYPUB_ACTOR_MODE ); ?>" <?php checked( ACTIVITYPUB_ACTOR_MODE, $value ); ?> />
186 <div>
187 <label for="actor-mode"><strong><?php esc_html_e( 'Author Profiles Only', 'activitypub' ); ?></strong></label>
188 <p class="description">
189 <?php echo wp_kses( __( 'Every author on this blog (with the <code>activitypub</code> capability) gets their own ActivityPub profile.', 'activitypub' ), array( 'code' => array() ) ); ?>
190 <strong>
191 <?php
192 echo wp_kses(
193 sprintf(
194 // translators: %s is a URL.
195 __( 'You can add/remove the capability in the <a href="%s">user settings.</a>', 'activitypub' ),
196 admin_url( '/users.php' )
197 ),
198 array( 'a' => array( 'href' => array() ) )
199 );
200 ?>
201 </strong>
202 <?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() ) ); ?>
203 </p>
204 </div>
205 </div>
206 <div class="row">
207 <input type="radio" id="blog-mode" name="activitypub_actor_mode" value="<?php echo esc_attr( ACTIVITYPUB_BLOG_MODE ); ?>" <?php checked( ACTIVITYPUB_BLOG_MODE, $value ); ?> />
208 <div>
209 <label for="blog-mode"><strong><?php esc_html_e( 'Blog profile only', 'activitypub' ); ?></strong></label>
210 <p class="description">
211 <?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' ); ?>
212 </p>
213 </div>
214 </div>
215 <div class="row">
216 <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 ); ?> />
217 <div>
218 <label for="actor-blog-mode"><strong><?php esc_html_e( 'Both author and blog profiles', 'activitypub' ); ?></strong></label>
219 <p class="description">
220 <?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' ); ?>
221 </p>
222 </div>
223 </div>
224 </fieldset>
225 <?php
226 }
227
228 /**
229 * Render custom post content field.
230 */
231 public static function render_custom_post_content_field() {
232 $value = get_option( 'activitypub_custom_post_content', ACTIVITYPUB_CUSTOM_POST_CONTENT );
233 ?>
234 <p>
235 <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>
236 <details>
237 <summary><?php esc_html_e( 'See a list of ActivityPub Template Tags.', 'activitypub' ); ?></summary>
238 <div class="description">
239 <ul>
240 <li><code>[ap_title]</code> - <?php esc_html_e( 'The post&#8217;s title.', 'activitypub' ); ?></li>
241 <li><code>[ap_content]</code> - <?php esc_html_e( 'The post&#8217;s content.', 'activitypub' ); ?></li>
242 <li><code>[ap_excerpt]</code> - <?php esc_html_e( 'The post&#8217;s excerpt (may be truncated).', 'activitypub' ); ?></li>
243 <li><code>[ap_permalink]</code> - <?php esc_html_e( 'The post&#8217;s permalink.', 'activitypub' ); ?></li>
244 <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>
245 <li><code>[ap_hashtags]</code> - <?php esc_html_e( 'The post&#8217;s tags as hashtags.', 'activitypub' ); ?></li>
246 </ul>
247 <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>
248 </div>
249 </details>
250 </p>
251 <?php
252 }
253
254 /**
255 * Render max image attachments field.
256 */
257 public static function render_max_image_attachments_field() {
258 $value = get_option( 'activitypub_max_image_attachments', ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS );
259 ?>
260 <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" />
261 <p class="description">
262 <?php
263 echo wp_kses(
264 sprintf(
265 // translators: %s is a number.
266 __( 'The number of media (images, audio, video) to attach to posts. Default: <code>%s</code>', 'activitypub' ),
267 esc_html( ACTIVITYPUB_MAX_IMAGE_ATTACHMENTS )
268 ),
269 'default'
270 );
271 ?>
272 </p>
273 <p class="description">
274 <em>
275 <?php esc_html_e( 'Note: audio and video attachments are only supported from Block Editor.', 'activitypub' ); ?>
276 </em>
277 </p>
278 <?php
279 }
280
281 /**
282 * Render support post types field.
283 */
284 public static function render_support_post_types_field() {
285 $post_types = \get_post_types( array( 'public' => true ), 'objects' );
286 $supported_post_types = \get_option( 'activitypub_support_post_types', array( 'post' ) );
287 ?>
288 <fieldset>
289 <?php esc_html_e( 'Automatically publish items of the selected post types to the fediverse:', 'activitypub' ); ?>
290 <ul>
291 <?php foreach ( $post_types as $post_type ) : ?>
292 <li>
293 <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 ) ); ?> />
294 <label for="activitypub_support_post_type_<?php echo esc_attr( $post_type->name ); ?>"><?php echo esc_html( $post_type->label ); ?></label>
295 <span class="description">
296 <?php echo esc_html( \Activitypub\get_post_type_description( $post_type ) ); ?>
297 </span>
298 </li>
299 <?php endforeach; ?>
300 </ul>
301 </fieldset>
302 <?php
303 }
304
305 /**
306 * Render allow interactions field.
307 */
308 public static function render_allow_interactions_field() {
309 if ( defined( 'ACTIVITYPUB_DISABLE_INCOMING_INTERACTIONS' ) && ACTIVITYPUB_DISABLE_INCOMING_INTERACTIONS ) {
310 echo '<p class="description">' . \esc_html__( 'âš  This setting is defined through server configuration by your blog&#8217;s administrator.', 'activitypub' ) . '</p>';
311 return;
312 }
313
314 $allow_likes = get_option( 'activitypub_allow_likes', '1' );
315 $allow_reposts = get_option( 'activitypub_allow_reposts', '1' );
316 $auto_approve = get_option( 'activitypub_auto_approve_reactions', '0' );
317 ?>
318 <fieldset>
319 <p>
320 <label>
321 <input type="checkbox" name="activitypub_allow_likes" value="1" <?php checked( '1', $allow_likes ); ?> />
322 <?php esc_html_e( 'Receive likes', 'activitypub' ); ?>
323 </label>
324 </p>
325 <p>
326 <label>
327 <input type="checkbox" name="activitypub_allow_reposts" value="1" <?php checked( '1', $allow_reposts ); ?> />
328 <?php esc_html_e( 'Receive reblogs (boosts)', 'activitypub' ); ?>
329 </label>
330 </p>
331 <p class="interactions description"><?php esc_html_e( 'Types of interactions from the Fediverse your blog should accept.', 'activitypub' ); ?></p>
332 <p>
333 <label>
334 <input type="checkbox" name="activitypub_auto_approve_reactions" value="1" <?php checked( '1', $auto_approve ); ?> />
335 <?php esc_html_e( 'Auto approve reactions', 'activitypub' ); ?>
336 </label>
337 </p>
338 </fieldset>
339 <?php
340 }
341
342 /**
343 * Render use hashtags field.
344 */
345 public static function render_use_hashtags_field() {
346 $value = get_option( 'activitypub_use_hashtags', '1' );
347 ?>
348 <p>
349 <label>
350 <input type="checkbox" id="activitypub_use_hashtags" name="activitypub_use_hashtags" value="1" <?php checked( '1', $value ); ?> />
351 <?php echo wp_kses( __( 'Add hashtags in the content as native tags and replace the <code>#tag</code> with the tag link.', 'activitypub' ), 'default' ); ?>
352 </label>
353 </p>
354 <?php
355 }
356
357 /**
358 * Render use OpenGraph field.
359 */
360 public static function render_use_opengraph_field() {
361 $value = get_option( 'activitypub_use_opengraph', '1' );
362 ?>
363 <p>
364 <label>
365 <input type="checkbox" id="activitypub_use_opengraph" name="activitypub_use_opengraph" value="1" <?php checked( '1', $value ); ?> />
366 <?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' ); ?>
367 </label>
368 </p>
369 <?php
370 }
371
372 /**
373 * Render attribution domains field.
374 */
375 public static function render_attribution_domains_field() {
376 $value = get_option( 'activitypub_attribution_domains', home_host() );
377 ?>
378 <textarea
379 id="activitypub_attribution_domains"
380 name="activitypub_attribution_domains"
381 class="large-text"
382 cols="50" rows="5"
383 placeholder="<?php echo esc_attr( home_host() ); ?>"
384 ><?php echo esc_textarea( $value ); ?></textarea>
385 <p class="description"><?php esc_html_e( 'Websites allowed to credit you, one per line. Protects from false attributions.', 'activitypub' ); ?></p>
386 <?php
387 }
388
389 /**
390 * Render relays field.
391 */
392 public static function render_relays_field() {
393 $value = \get_option( 'activitypub_relays', array() );
394 ?>
395 <textarea
396 id="activitypub_relays"
397 name="activitypub_relays"
398 class="large-text"
399 cols="50"
400 rows="5"
401 ><?php echo \esc_textarea( implode( PHP_EOL, $value ) ); ?></textarea>
402 <p class="description">
403 <?php echo \wp_kses( \__( 'A <strong>Fediverse-Relay</strong> distributes content across instances, expanding reach, engagement, and discoverability, especially for smaller instances.', 'activitypub' ), 'default' ); ?>
404 </p>
405 <p class="description">
406 <?php
407 echo \wp_kses(
408 \__( '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' ),
409 array(
410 'strong' => array(),
411 'code' => array(),
412 )
413 );
414 ?>
415 <?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' ); ?>
416 </p>
417 <?php
418 }
419
420 /**
421 * Render moderation section description.
422 */
423 public static function render_moderation_section_description() {
424 echo '<p>' . \esc_html__( 'Configure site-wide moderation settings. These blocks will affect all users and ActivityPub content on your site.', 'activitypub' ) . '</p>';
425 }
426
427 /**
428 * Render site blocked domains field.
429 */
430 public static function render_site_blocked_domains_field() {
431 $blocked_domains = Moderation::get_site_blocks()['domains'];
432 ?>
433 <p class="description"><?php \esc_html_e( 'Block entire ActivityPub instances by domain name.', 'activitypub' ); ?></p>
434
435 <div class="activitypub-site-block-list">
436 <?php if ( ! empty( $blocked_domains ) ) : ?>
437 <table class="widefat striped activitypub-site-blocked-domain" role="presentation" style="max-width: 500px; margin: 15px 0;">
438 <?php foreach ( $blocked_domains as $domain ) : ?>
439 <tr>
440 <td><?php echo \esc_html( $domain ); ?></td>
441 <td style="width: 80px;">
442 <button type="button" class="button button-small remove-site-block-btn" data-type="domain" data-value="<?php echo \esc_attr( $domain ); ?>">
443 <?php \esc_html_e( 'Remove', 'activitypub' ); ?>
444 </button>
445 </td>
446 </tr>
447 <?php endforeach; ?>
448 </table>
449 <?php endif; ?>
450
451 <div class="add-site-block-form" style="display: flex; max-width: 500px; gap: 8px;">
452 <input type="text" class="regular-text" id="new_site_domain" placeholder="<?php \esc_attr_e( 'example.com', 'activitypub' ); ?>" style="flex: 1; min-width: 0;" />
453 <button type="button" class="button add-site-block-btn" data-type="domain" style="flex-shrink: 0; white-space: nowrap;">
454 <?php \esc_html_e( 'Add Block', 'activitypub' ); ?>
455 </button>
456 </div>
457 </div>
458 <?php
459 }
460
461 /**
462 * Render site blocked keywords field.
463 */
464 public static function render_site_blocked_keywords_field() {
465 $blocked_keywords = Moderation::get_site_blocks()['keywords'];
466 ?>
467 <p class="description"><?php \esc_html_e( 'Block ActivityPub content containing specific keywords.', 'activitypub' ); ?></p>
468
469 <div class="activitypub-site-block-list">
470 <?php if ( ! empty( $blocked_keywords ) ) : ?>
471 <table class="widefat striped activitypub-site-blocked-keyword" role="presentation" style="max-width: 500px; margin: 15px 0;">
472 <?php foreach ( $blocked_keywords as $keyword ) : ?>
473 <tr>
474 <td><?php echo \esc_html( $keyword ); ?></td>
475 <td style="width: 80px;">
476 <button type="button" class="button button-small remove-site-block-btn" data-type="keyword" data-value="<?php echo \esc_attr( $keyword ); ?>">
477 <?php \esc_html_e( 'Remove', 'activitypub' ); ?>
478 </button>
479 </td>
480 </tr>
481 <?php endforeach; ?>
482 </table>
483 <?php endif; ?>
484
485 <div class="add-site-block-form" style="display: flex; max-width: 500px; gap: 8px;">
486 <input type="text" class="regular-text" id="new_site_keyword" placeholder="<?php \esc_attr_e( 'spam keyword', 'activitypub' ); ?>" style="flex: 1; min-width: 0;" />
487 <button type="button" class="button add-site-block-btn" data-type="keyword" style="flex-shrink: 0; white-space: nowrap;">
488 <?php \esc_html_e( 'Add Block', 'activitypub' ); ?>
489 </button>
490 </div>
491 </div>
492 <?php
493 }
494 }
495