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-user-settings-fields.php

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

408 lines 14.8 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * ActivityPub User Settings Fields Handler.
4 *
5 * @package Activitypub
6 */
7
8 namespace Activitypub\WP_Admin;
9
10 use Activitypub\Collection\Actors;
11 use Activitypub\Collection\Extra_Fields;
12 use Activitypub\Moderation;
13
14 /**
15 * Class to handle all user settings fields and callbacks.
16 */
17 class User_Settings_Fields {
18 /**
19 * Initialize the settings fields.
20 */
21 public static function init() {
22 \add_action( 'load-profile.php', array( self::class, 'register_settings' ) );
23 }
24
25 /**
26 * Register all settings fields.
27 */
28 public static function register_settings() {
29 // Mark checklist item as done.
30 \update_option( 'activitypub_checklist_profile_setup_visited', '1' );
31
32 \add_settings_section(
33 'activitypub_user_profile',
34 \esc_html__( 'ActivityPub', 'activitypub' ),
35 array( self::class, 'section_description' ),
36 'activitypub_user_settings',
37 array(
38 'before_section' => '<section id="activitypub">',
39 'after_section' => '</section>',
40 )
41 );
42
43 \add_settings_field(
44 'activitypub_profile_url',
45 \esc_html__( 'Profile URL', 'activitypub' ),
46 array( self::class, 'profile_url_callback' ),
47 'activitypub_user_settings',
48 'activitypub_user_profile'
49 );
50
51 \add_settings_field(
52 'activitypub_description',
53 \esc_html__( 'Biography', 'activitypub' ),
54 array( self::class, 'description_callback' ),
55 'activitypub_user_settings',
56 'activitypub_user_profile',
57 array( 'label_for' => 'activitypub_description' )
58 );
59
60 \add_settings_field(
61 'activitypub_header_image',
62 \esc_html__( 'Header Image', 'activitypub' ),
63 array( self::class, 'header_image_callback' ),
64 'activitypub_user_settings',
65 'activitypub_user_profile',
66 array( 'label_for' => 'activitypub_header_image' )
67 );
68
69 \add_settings_field(
70 'activitypub_notifications',
71 \esc_html__( 'Email Notifications', 'activitypub' ),
72 array( self::class, 'notifications_callback' ),
73 'activitypub_user_settings',
74 'activitypub_user_profile'
75 );
76
77 \add_settings_field(
78 'activitypub_extra_fields',
79 \esc_html__( 'Extra Fields', 'activitypub' ),
80 array( self::class, 'extra_fields_callback' ),
81 'activitypub_user_settings',
82 'activitypub_user_profile'
83 );
84
85 \add_settings_field(
86 'activitypub_also_known_as',
87 \esc_html__( 'Account Aliases', 'activitypub' ),
88 array( self::class, 'also_known_as_callback' ),
89 'activitypub_user_settings',
90 'activitypub_user_profile',
91 array( 'label_for' => 'activitypub_also_known_as' )
92 );
93
94 \add_settings_field(
95 'activitypub_hide_social_graph',
96 \__( 'Followers and Followings', 'activitypub' ),
97 array( self::class, 'hide_followers_callback' ),
98 'activitypub_user_settings',
99 'activitypub_user_profile'
100 );
101
102 // Add moderation section.
103 \add_settings_section(
104 'activitypub_user_moderation',
105 \esc_html__( 'Moderation', 'activitypub' ),
106 array( self::class, 'moderation_section_description' ),
107 'activitypub_user_settings',
108 array(
109 'before_section' => '<section id="activitypub-moderation">',
110 'after_section' => '</section>',
111 )
112 );
113
114 \add_settings_field(
115 'activitypub_user_blocked_domains',
116 \esc_html__( 'Blocked Domains', 'activitypub' ),
117 array( self::class, 'blocked_domains_callback' ),
118 'activitypub_user_settings',
119 'activitypub_user_moderation'
120 );
121
122 \add_settings_field(
123 'activitypub_user_blocked_keywords',
124 \esc_html__( 'Blocked Keywords', 'activitypub' ),
125 array( self::class, 'blocked_keywords_callback' ),
126 'activitypub_user_settings',
127 'activitypub_user_moderation'
128 );
129 }
130
131 /**
132 * Section description callback.
133 */
134 public static function section_description() {
135 echo '<p>' . \esc_html__( 'Define what others can see on your public Fediverse profile and next to your posts. With a profile picture and a fully completed profile, you are more likely to gain interactions and followers.', 'activitypub' ) . '</p>';
136 echo '<p>' . \esc_html__( 'The ActivityPub plugin tries to take as much information as possible from your profile settings. However, the following settings are not supported by WordPress or should be adjusted independently of the WordPress settings.', 'activitypub' ) . '</p>';
137 }
138
139 /**
140 * Profile URL field callback.
141 */
142 public static function profile_url_callback() {
143 $user = Actors::get_by_id( \get_current_user_id() );
144 ?>
145 <p>
146 <?php
147 \printf(
148 // translators: 1: the webfinger resource, 2: the author URL.
149 \esc_html__( '%1$s or %2$s', 'activitypub' ),
150 '<code>' . \esc_html( $user->get_webfinger() ) . '</code>',
151 '<code>' . \esc_url( $user->get_url() ) . '</code>'
152 );
153 ?>
154 </p>
155 <p class="description">
156 <?php
157 \printf(
158 // translators: the webfinger resource.
159 \esc_html__( 'Follow "@%s" by searching for it on Mastodon, Friendica, etc.', 'activitypub' ),
160 \esc_html( $user->get_webfinger() )
161 );
162 ?>
163 </p>
164 <?php
165 }
166
167 /**
168 * Description field callback.
169 */
170 public static function description_callback() {
171 $description = \get_user_option( 'activitypub_description', \get_current_user_id() );
172 $placeholder = \get_user_meta( \get_current_user_id(), 'description', true );
173 ?>
174 <textarea name="activitypub_description" id="activitypub_description" rows="5" cols="30" placeholder="<?php echo \esc_attr( $placeholder ); ?>"><?php echo \esc_html( $description ); ?></textarea>
175 <p class="description"><?php \esc_html_e( 'If you wish to use different biographical info for the fediverse, enter your alternate bio here.', 'activitypub' ); ?></p>
176 <?php
177 }
178
179 /**
180 * Header image field callback.
181 */
182 public static function header_image_callback() {
183 $header_image = \get_user_option( 'activitypub_header_image', \get_current_user_id() );
184 $classes_for_upload_button = 'button upload-button button-add-media button-add-header-image';
185 $classes_for_update_button = 'button';
186 $classes_for_wrapper = '';
187
188 if ( (int) $header_image ) {
189 $classes_for_wrapper .= ' has-header-image';
190 $classes_for_button = $classes_for_update_button;
191 $classes_for_button_on_change = $classes_for_upload_button;
192 } else {
193 $classes_for_wrapper .= ' hidden';
194 $classes_for_button = $classes_for_upload_button;
195 $classes_for_button_on_change = $classes_for_update_button;
196 }
197 ?>
198 <div id="activitypub-header-image-preview-wrapper" class="<?php echo \esc_attr( $classes_for_wrapper ); ?>">
199 <img id="activitypub-header-image-preview" src="<?php echo \esc_url( \wp_get_attachment_url( $header_image ) ); ?>" style="max-width: 100%;" alt="" />
200 </div>
201 <button
202 type="button"
203 id="activitypub-choose-from-library-button"
204 class="<?php echo \esc_attr( $classes_for_button ); ?>"
205 data-alt-classes="<?php echo \esc_attr( $classes_for_button_on_change ); ?>"
206 data-choose-text="<?php \esc_attr_e( 'Choose a Header Image', 'activitypub' ); ?>"
207 data-update-text="<?php \esc_attr_e( 'Change Header Image', 'activitypub' ); ?>"
208 data-update="<?php \esc_attr_e( 'Set as Header Image', 'activitypub' ); ?>"
209 data-width="1500"
210 data-height="500"
211 <?php
212 if ( ! \current_user_can( 'edit_others_posts' ) ) :
213 \printf( 'data-user-id="%s"', \esc_attr( \get_current_user_id() ) );
214 endif;
215 ?>
216 data-state="<?php echo \esc_attr( (int) $header_image ); ?>">
217 <?php echo (int) $header_image ? \esc_html__( 'Change Header Image', 'activitypub' ) : \esc_html__( 'Choose a Header Image', 'activitypub' ); ?>
218 </button>
219 <button
220 id="activitypub-remove-header-image"
221 type="button"
222 <?php echo (int) $header_image ? 'class="button button-secondary reset"' : 'class="button button-secondary reset hidden"'; ?>>
223 <?php \esc_html_e( 'Remove Header Image', 'activitypub' ); ?>
224 </button>
225 <input type="hidden" name="activitypub_header_image" id="activitypub_header_image" value="<?php echo \esc_attr( $header_image ); ?>">
226 <?php
227 }
228
229 /**
230 * Notifications field callback.
231 */
232 public static function notifications_callback() {
233 ?>
234 <fieldset id="activitypub-notifications">
235 <p>
236 <label>
237 <input type="checkbox" name="activitypub_mailer_new_follower" id="activitypub_mailer_new_follower" value="1" <?php \checked( 1, \get_user_option( 'activitypub_mailer_new_follower' ) ); ?> />
238 <?php \esc_html_e( 'New Followers', 'activitypub' ); ?>
239 </label>
240 </p>
241 <p>
242 <label>
243 <input type="checkbox" name="activitypub_mailer_new_dm" id="activitypub_mailer_new_dm" value="1" <?php \checked( 1, \get_user_option( 'activitypub_mailer_new_dm' ) ); ?> />
244 <?php \esc_html_e( 'Direct Messages', 'activitypub' ); ?>
245 </label>
246 </p>
247 <p>
248 <label>
249 <input type="checkbox" name="activitypub_mailer_new_mention" id="activitypub_mailer_new_mention" value="1" <?php \checked( 1, \get_user_option( 'activitypub_mailer_new_mention' ) ); ?> />
250 <?php \esc_html_e( 'New Mentions', 'activitypub' ); ?>
251 </label>
252 </p>
253 </fieldset>
254 <?php
255 }
256
257 /**
258 * Extra fields callback.
259 */
260 public static function extra_fields_callback() {
261 $extra_fields = Extra_Fields::get_actor_fields( \get_current_user_id() );
262 ?>
263 <p class="description">
264 <?php \esc_html_e( 'Your homepage, social profiles, pronouns, age, anything you want.', 'activitypub' ); ?>
265 </p>
266
267 <?php if ( ! empty( $extra_fields ) ) : ?>
268 <table class="widefat striped activitypub-extra-fields" role="presentation" style="margin: 15px 0;">
269 <?php foreach ( $extra_fields as $extra_field ) : ?>
270 <tr>
271 <td><?php echo \esc_html( $extra_field->post_title ); ?></td>
272 <td><?php echo \wp_kses_post( \get_the_excerpt( $extra_field ) ); ?></td>
273 <td>
274 <a href="<?php echo \esc_url( \get_edit_post_link( $extra_field->ID ) ); ?>" class="button">
275 <?php \esc_html_e( 'Edit', 'activitypub' ); ?>
276 </a>
277 </td>
278 </tr>
279 <?php endforeach; ?>
280 </table>
281 <?php endif; ?>
282
283 <p class="extra-fields-nav">
284 <a href="<?php echo \esc_url( \admin_url( '/post-new.php?post_type=ap_extrafield' ) ); ?>" class="button">
285 <?php \esc_html_e( 'Add new', 'activitypub' ); ?>
286 </a>
287 <a href="<?php echo \esc_url( \admin_url( '/edit.php?post_type=ap_extrafield' ) ); ?>">
288 <?php \esc_html_e( 'Manage all', 'activitypub' ); ?>
289 </a>
290 </p>
291 <?php
292 }
293
294 /**
295 * Also Known As field callback.
296 */
297 public static function also_known_as_callback() {
298 $also_known_as = \get_user_option( 'activitypub_also_known_as', \get_current_user_id() );
299 ?>
300 <textarea
301 class="large-text"
302 name="activitypub_also_known_as"
303 id="activitypub_also_known_as"
304 rows="5"
305 ><?php echo \esc_textarea( implode( PHP_EOL, (array) $also_known_as ) ); ?></textarea>
306 <p class="description">
307 <?php \esc_html_e( 'If you&#8217;re moving from another account to this one, you&#8217;ll need to create an alias here first before transferring your followers. This step is safe, reversible, and doesn&#8217;t affect anything on its own. The migration itself is initiated from your old account.', 'activitypub' ); ?>
308 </p>
309 <p class="description">
310 <?php echo \wp_kses_post( \__( 'Enter one account per line. Profile links or usernames like <code>@username@example.com</code> are accepted and will be automatically normalized to the correct format.', 'activitypub' ) ); ?>
311 </p>
312 <?php
313 }
314
315 /**
316 * Moderation section description callback.
317 */
318 public static function moderation_section_description() {
319 echo '<p>' . \esc_html__( 'Configure personal blocks to filter ActivityPub content you don\'t want to see.', 'activitypub' ) . '</p>';
320 }
321
322 /**
323 * Blocked domains field callback.
324 */
325 public static function blocked_domains_callback() {
326 $user_id = \get_current_user_id();
327 $blocked_domains = Moderation::get_user_blocks( $user_id )['domains'];
328 ?>
329 <p class="description"><?php \esc_html_e( 'Block entire ActivityPub instances by domain name.', 'activitypub' ); ?></p>
330
331 <div class="activitypub-user-block-list" data-user-id="<?php echo \esc_attr( $user_id ); ?>">
332 <?php if ( ! empty( $blocked_domains ) ) : ?>
333 <table class="widefat striped activitypub-blocked-domain" role="presentation" style="max-width: 500px; margin: 15px 0;">
334 <?php foreach ( $blocked_domains as $domain ) : ?>
335 <tr>
336 <td><?php echo \esc_html( $domain ); ?></td>
337 <td style="width: 80px;">
338 <button type="button" class="button button-small remove-user-block-btn" data-type="domain" data-value="<?php echo \esc_attr( $domain ); ?>">
339 <?php \esc_html_e( 'Remove', 'activitypub' ); ?>
340 </button>
341 </td>
342 </tr>
343 <?php endforeach; ?>
344 </table>
345 <?php endif; ?>
346
347 <div class="add-user-block-form" style="display: flex; max-width: 500px; gap: 8px;">
348 <input type="text" class="regular-text" id="new_user_domain" placeholder="<?php \esc_attr_e( 'example.com', 'activitypub' ); ?>" style="flex: 1; min-width: 0;" />
349 <button type="button" class="button add-user-block-btn" data-type="domain" style="flex-shrink: 0; white-space: nowrap;">
350 <?php \esc_html_e( 'Add Block', 'activitypub' ); ?>
351 </button>
352 </div>
353 </div>
354 <?php
355 }
356
357 /**
358 * Blocked keywords field callback.
359 */
360 public static function blocked_keywords_callback() {
361 $user_id = \get_current_user_id();
362 $blocked_keywords = Moderation::get_user_blocks( $user_id )['keywords'];
363 ?>
364 <p class="description"><?php \esc_html_e( 'Block ActivityPub content containing specific keywords.', 'activitypub' ); ?></p>
365
366 <div class="activitypub-user-block-list" data-user-id="<?php echo \esc_attr( $user_id ); ?>">
367 <?php if ( ! empty( $blocked_keywords ) ) : ?>
368 <table class="widefat striped activitypub-blocked-keyword" role="presentation" style="max-width: 500px; margin: 15px 0;">
369 <?php foreach ( $blocked_keywords as $keyword ) : ?>
370 <tr>
371 <td><?php echo \esc_html( $keyword ); ?></td>
372 <td style="width: 80px;">
373 <button type="button" class="button button-small remove-user-block-btn" data-type="keyword" data-value="<?php echo \esc_attr( $keyword ); ?>">
374 <?php \esc_html_e( 'Remove', 'activitypub' ); ?>
375 </button>
376 </td>
377 </tr>
378 <?php endforeach; ?>
379 </table>
380 <?php endif; ?>
381
382 <div class="add-user-block-form" style="display: flex; max-width: 500px; gap: 8px;">
383 <input type="text" class="regular-text" id="new_user_keyword" placeholder="<?php \esc_attr_e( 'spam keyword', 'activitypub' ); ?>" style="flex: 1; min-width: 0;" />
384 <button type="button" class="button add-user-block-btn" data-type="keyword" style="flex-shrink: 0; white-space: nowrap;">
385 <?php \esc_html_e( 'Add Block', 'activitypub' ); ?>
386 </button>
387 </div>
388 </div>
389 <?php
390 }
391
392 /**
393 * Hide Social Graph field callback.
394 */
395 public static function hide_followers_callback() {
396 $hide_followers = \get_user_option( 'activitypub_hide_social_graph', \get_current_user_id() );
397 ?>
398 <label>
399 <input type="checkbox" name="activitypub_hide_social_graph" id="activitypub_hide_social_graph" value="1" <?php \checked( '1', $hide_followers ); ?> />
400 <?php \esc_html_e( 'Hide Followers and Following on Profile', 'activitypub' ); ?>
401 </label>
402 <p class="description">
403 <?php esc_html_e( 'People you follow will still see that you follow them.', 'activitypub' ); ?>
404 </p>
405 <?php
406 }
407 }
408