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

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