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

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

232 lines 8.3 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 /**
11 * Class to handle all user settings fields and callbacks.
12 */
13 class User_Settings_Fields {
14 /**
15 * Initialize the settings fields.
16 */
17 public static function init() {
18 add_action( 'load-profile.php', array( self::class, 'register_settings' ) );
19 }
20
21 /**
22 * Register all settings fields.
23 */
24 public static function register_settings() {
25 \add_settings_section(
26 'activitypub_user_profile',
27 \esc_html__( 'ActivityPub', 'activitypub' ),
28 array( self::class, 'section_description' ),
29 'activitypub_user_settings'
30 );
31
32 \add_settings_field(
33 'activitypub_profile_url',
34 \esc_html__( 'Profile URL', 'activitypub' ),
35 array( self::class, 'profile_url_callback' ),
36 'activitypub_user_settings',
37 'activitypub_user_profile'
38 );
39
40 \add_settings_field(
41 'activitypub_description',
42 \esc_html__( 'Biography', 'activitypub' ),
43 array( self::class, 'description_callback' ),
44 'activitypub_user_settings',
45 'activitypub_user_profile',
46 array( 'label_for' => 'activitypub_description' )
47 );
48
49 \add_settings_field(
50 'activitypub_header_image',
51 \esc_html__( 'Header Image', 'activitypub' ),
52 array( self::class, 'header_image_callback' ),
53 'activitypub_user_settings',
54 'activitypub_user_profile',
55 array( 'label_for' => 'activitypub_header_image' )
56 );
57
58 \add_settings_field(
59 'activitypub_extra_fields',
60 \esc_html__( 'Extra Fields', 'activitypub' ),
61 array( self::class, 'extra_fields_callback' ),
62 'activitypub_user_settings',
63 'activitypub_user_profile'
64 );
65
66 \add_settings_field(
67 'activitypub_also_known_as',
68 \esc_html__( 'Account Aliases', 'activitypub' ),
69 array( self::class, 'also_known_as_callback' ),
70 'activitypub_user_settings',
71 'activitypub_user_profile',
72 array( 'label_for' => 'activitypub_blog_user_also_known_as' )
73 );
74 }
75
76 /**
77 * Section description callback.
78 */
79 public static function section_description() {
80 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>';
81 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>';
82 }
83
84 /**
85 * Profile URL field callback.
86 */
87 public static function profile_url_callback() {
88 $user = \Activitypub\Collection\Actors::get_by_id( \get_current_user_id() );
89 ?>
90 <p>
91 <?php
92 \printf(
93 // translators: 1: the webfinger resource, 2: the author URL.
94 \esc_html__( '%1$s or %2$s', 'activitypub' ),
95 '<code>' . \esc_html( $user->get_webfinger() ) . '</code>',
96 '<code>' . \esc_url( $user->get_url() ) . '</code>'
97 );
98 ?>
99 </p>
100 <p class="description">
101 <?php
102 \printf(
103 // translators: the webfinger resource.
104 \esc_html__( 'Follow "@%s" by searching for it on Mastodon, Friendica, etc.', 'activitypub' ),
105 \esc_html( $user->get_webfinger() )
106 );
107 ?>
108 </p>
109 <?php
110 }
111
112 /**
113 * Description field callback.
114 */
115 public static function description_callback() {
116 $description = \get_user_option( 'activitypub_description', \get_current_user_id() );
117 $placeholder = \get_user_meta( \get_current_user_id(), 'description', true );
118 ?>
119 <textarea name="activitypub_description" id="activitypub_description" rows="5" cols="30" placeholder="<?php echo \esc_attr( $placeholder ); ?>"><?php echo \esc_html( $description ); ?></textarea>
120 <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>
121 <?php
122 }
123
124 /**
125 * Header image field callback.
126 */
127 public static function header_image_callback() {
128 $header_image = \get_user_option( 'activitypub_header_image', \get_current_user_id() );
129 $classes_for_upload_button = 'button upload-button button-add-media button-add-header-image';
130 $classes_for_update_button = 'button';
131 $classes_for_wrapper = '';
132
133 if ( (int) $header_image ) {
134 $classes_for_wrapper .= ' has-header-image';
135 $classes_for_button = $classes_for_update_button;
136 $classes_for_button_on_change = $classes_for_upload_button;
137 } else {
138 $classes_for_wrapper .= ' hidden';
139 $classes_for_button = $classes_for_upload_button;
140 $classes_for_button_on_change = $classes_for_update_button;
141 }
142 ?>
143 <div id="activitypub-header-image-preview-wrapper" class="<?php echo \esc_attr( $classes_for_wrapper ); ?>">
144 <img id="activitypub-header-image-preview" src="<?php echo \esc_url( \wp_get_attachment_url( $header_image ) ); ?>" style="max-width: 100%;" alt="" />
145 </div>
146 <button
147 type="button"
148 id="activitypub-choose-from-library-button"
149 class="<?php echo \esc_attr( $classes_for_button ); ?>"
150 data-alt-classes="<?php echo \esc_attr( $classes_for_button_on_change ); ?>"
151 data-choose-text="<?php \esc_attr_e( 'Choose a Header Image', 'activitypub' ); ?>"
152 data-update-text="<?php \esc_attr_e( 'Change Header Image', 'activitypub' ); ?>"
153 data-update="<?php \esc_attr_e( 'Set as Header Image', 'activitypub' ); ?>"
154 data-width="1500"
155 data-height="500"
156 <?php
157 if ( ! \current_user_can( 'edit_others_posts' ) ) :
158 \printf( 'data-user-id="%s"', \esc_attr( \get_current_user_id() ) );
159 endif;
160 ?>
161 data-state="<?php echo \esc_attr( (int) $header_image ); ?>">
162 <?php echo (int) $header_image ? \esc_html__( 'Change Header Image', 'activitypub' ) : \esc_html__( 'Choose a Header Image', 'activitypub' ); ?>
163 </button>
164 <button
165 id="activitypub-remove-header-image"
166 type="button"
167 <?php echo (int) $header_image ? 'class="button button-secondary reset"' : 'class="button button-secondary reset hidden"'; ?>>
168 <?php \esc_html_e( 'Remove Header Image', 'activitypub' ); ?>
169 </button>
170 <input type="hidden" name="activitypub_header_image" id="activitypub_header_image" value="<?php echo \esc_attr( $header_image ); ?>">
171 <?php
172 }
173
174 /**
175 * Extra fields callback.
176 */
177 public static function extra_fields_callback() {
178 $extra_fields = \Activitypub\Collection\Extra_Fields::get_actor_fields( \get_current_user_id() );
179 ?>
180 <p class="description">
181 <?php \esc_html_e( 'Your homepage, social profiles, pronouns, age, anything you want.', 'activitypub' ); ?>
182 </p>
183
184 <?php if ( ! empty( $extra_fields ) ) : ?>
185 <table class="widefat striped activitypub-extra-fields" role="presentation" style="margin: 15px 0;">
186 <?php foreach ( $extra_fields as $extra_field ) : ?>
187 <tr>
188 <td><?php echo \esc_html( $extra_field->post_title ); ?></td>
189 <td><?php echo \wp_kses_post( \get_the_excerpt( $extra_field ) ); ?></td>
190 <td>
191 <a href="<?php echo \esc_url( \get_edit_post_link( $extra_field->ID ) ); ?>" class="button">
192 <?php \esc_html_e( 'Edit', 'activitypub' ); ?>
193 </a>
194 </td>
195 </tr>
196 <?php endforeach; ?>
197 </table>
198 <?php endif; ?>
199
200 <p class="extra-fields-nav">
201 <a href="<?php echo \esc_url( \admin_url( '/post-new.php?post_type=ap_extrafield' ) ); ?>" class="button">
202 <?php \esc_html_e( 'Add new', 'activitypub' ); ?>
203 </a>
204 <a href="<?php echo \esc_url( \admin_url( '/edit.php?post_type=ap_extrafield' ) ); ?>">
205 <?php \esc_html_e( 'Manage all', 'activitypub' ); ?>
206 </a>
207 </p>
208 <?php
209 }
210
211 /**
212 * Also Known As field callback.
213 */
214 public static function also_known_as_callback() {
215 $also_known_as = \get_user_option( 'activitypub_also_known_as', \get_current_user_id() );
216 ?>
217 <textarea
218 class="large-text"
219 name="activitypub_blog_user_also_known_as"
220 id="activitypub_blog_user_also_known_as"
221 rows="5"
222 ><?php echo \esc_textarea( implode( PHP_EOL, (array) $also_known_as ) ); ?></textarea>
223 <p class="description">
224 <?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' ); ?>
225 </p>
226 <p class="description">
227 <?php \esc_html_e( 'Enter one URL per line.', 'activitypub' ); ?>
228 </p>
229 <?php
230 }
231 }
232