PluginProbe
ActivityPub / trunk
ActivityPub vtrunk
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-blog-settings-fields.php

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

344 lines 12.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * ActivityPub Blog 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\Model\Blog;
13
14 /**
15 * Class to handle all blog settings fields and callbacks.
16 */
17 class Blog_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' ) );
23 }
24
25 /**
26 * Register all settings fields.
27 */
28 public static function register_settings() {
29 // If we're in blog mode, and we're on the blog profile tab, mark the profile setup step as done.
30 if ( isset( $_GET['tab'] ) && 'blog-profile' === \sanitize_key( $_GET['tab'] ) && ACTIVITYPUB_BLOG_MODE === \get_option( 'activitypub_actor_mode' ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
31 \update_option( 'activitypub_checklist_profile_setup_visited', '1' );
32 }
33
34 \add_settings_section(
35 'activitypub_blog_profile',
36 \__( 'Blog Profile', 'activitypub' ),
37 '__return_empty_string',
38 'activitypub_blog_settings'
39 );
40
41 \add_settings_field(
42 'activitypub_blog_avatar',
43 \__( 'Manage Avatar', 'activitypub' ),
44 array( self::class, 'avatar_callback' ),
45 'activitypub_blog_settings',
46 'activitypub_blog_profile'
47 );
48
49 \add_settings_field(
50 'activitypub_header_image',
51 \__( 'Manage Header Image', 'activitypub' ),
52 array( self::class, 'header_image_callback' ),
53 'activitypub_blog_settings',
54 'activitypub_blog_profile'
55 );
56
57 // Don't show profile ID field when relay mode is enabled.
58 if ( ! \get_option( 'activitypub_relay_mode', false ) ) {
59 \add_settings_field(
60 'activitypub_blog_identifier',
61 \__( 'Change Profile ID', 'activitypub' ),
62 array( self::class, 'profile_id_callback' ),
63 'activitypub_blog_settings',
64 'activitypub_blog_profile',
65 array( 'label_for' => 'activitypub_blog_identifier' )
66 );
67 }
68
69 \add_settings_field(
70 'activitypub_blog_description',
71 \__( 'Change Description', 'activitypub' ),
72 array( self::class, 'description_callback' ),
73 'activitypub_blog_settings',
74 'activitypub_blog_profile',
75 array( 'label_for' => 'activitypub_blog_description' )
76 );
77
78 \add_settings_field(
79 'activitypub_notifications',
80 \esc_html__( 'Email Notifications', 'activitypub' ),
81 array( self::class, 'notifications_callback' ),
82 'activitypub_blog_settings',
83 'activitypub_blog_profile'
84 );
85
86 \add_settings_field(
87 'activitypub_extra_fields',
88 \__( 'Extra Fields', 'activitypub' ),
89 array( self::class, 'extra_fields_callback' ),
90 'activitypub_blog_settings',
91 'activitypub_blog_profile'
92 );
93
94 \add_settings_field(
95 'activitypub_blog_user_also_known_as',
96 \__( 'Account Aliases', 'activitypub' ),
97 array( self::class, 'also_known_as_callback' ),
98 'activitypub_blog_settings',
99 'activitypub_blog_profile'
100 );
101
102 \add_settings_field(
103 'activitypub_hide_social_graph',
104 \__( 'Followers and Followings', 'activitypub' ),
105 array( self::class, 'hide_followers_callback' ),
106 'activitypub_blog_settings',
107 'activitypub_blog_profile'
108 );
109 }
110
111 /**
112 * Avatar field callback.
113 */
114 public static function avatar_callback() {
115 ?>
116 <?php if ( \has_site_icon() ) : ?>
117 <p><img src="<?php echo \esc_url( \get_site_icon_url( 50 ) ); ?>" alt="" /></p>
118 <?php endif; ?>
119 <p class="description">
120 <?php
121 echo \wp_kses(
122 \sprintf(
123 // translators: %s is a URL.
124 \__( 'The ActivityPub plugin uses the WordPress Site Icon as Avatar for the Blog-Profile, you can change the Site Icon in the "<a href="%s">General Settings</a>" of WordPress.', 'activitypub' ),
125 \esc_url( \admin_url( 'options-general.php' ) )
126 ),
127 'default'
128 );
129 ?>
130 </p>
131 <?php
132 }
133
134 /**
135 * Header image field callback.
136 */
137 public static function header_image_callback() {
138 $classes_for_button = 'button upload-button button-add-media button-add-header-image';
139 $classes_for_button_on_change = 'button';
140 $classes_for_wrapper = ' hidden';
141
142 if ( (int) \get_option( 'activitypub_header_image', 0 ) ) {
143 $classes_for_wrapper = ' has-header-image';
144 $classes_for_button_on_change = $classes_for_button;
145 $classes_for_button = 'button';
146 }
147 ?>
148 <div id="activitypub-header-image-preview-wrapper" class="<?php echo \esc_attr( $classes_for_wrapper ); ?>">
149 <img id="activitypub-header-image-preview" src="<?php echo \esc_url( \wp_get_attachment_url( \get_option( 'activitypub_header_image' ) ) ); ?>" style="max-width: 100%;" alt="" />
150 </div>
151 <button
152 type="button"
153 id="activitypub-choose-from-library-button"
154 class="<?php echo \esc_attr( $classes_for_button ); ?>"
155 data-alt-classes="<?php echo \esc_attr( $classes_for_button_on_change ); ?>"
156 data-choose-text="<?php \esc_attr_e( 'Choose a Header Image', 'activitypub' ); ?>"
157 data-update-text="<?php \esc_attr_e( 'Change Header Icon', 'activitypub' ); ?>"
158 data-update="<?php \esc_attr_e( 'Set as Header Image', 'activitypub' ); ?>"
159 data-width="1500"
160 data-height="500"
161 data-state="<?php echo \esc_attr( (int) \get_option( 'activitypub_header_image', 0 ) ); ?>">
162 <?php if ( (int) \get_option( 'activitypub_header_image', 0 ) ) : ?>
163 <?php \esc_html_e( 'Change Header Image', 'activitypub' ); ?>
164 <?php else : ?>
165 <?php \esc_html_e( 'Choose a Header Image', 'activitypub' ); ?>
166 <?php endif; ?>
167 </button>
168 <button
169 id="activitypub-remove-header-image"
170 type="button"
171 <?php echo (int) \get_option( 'activitypub_header_image', 0 ) ? 'class="button button-secondary reset"' : 'class="button button-secondary reset hidden"'; ?>>
172 <?php \esc_html_e( 'Remove Header Image', 'activitypub' ); ?>
173 </button>
174 <input type="hidden" name="activitypub_header_image" id="activitypub_header_image" value="<?php echo \esc_attr( \get_option( 'activitypub_header_image' ) ); ?>">
175 <?php
176 }
177
178 /**
179 * Profile ID field callback.
180 */
181 public static function profile_id_callback() {
182 ?>
183 <label for="activitypub_blog_identifier">
184 <input id="activitypub_blog_identifier" class="blog-user-identifier" name="activitypub_blog_identifier" type="text" value="<?php echo \esc_attr( \get_option( 'activitypub_blog_identifier', Blog::get_default_username() ) ); ?>" />
185 @<?php echo \esc_html( \wp_parse_url( \home_url(), PHP_URL_HOST ) ); ?>
186 </label>
187 <p class="description">
188 <?php \esc_html_e( 'This profile name will federate all posts written on your blog, regardless of the author who posted it.', 'activitypub' ); ?>
189 </p>
190 <p class="description">
191 <strong>
192 <?php \esc_html_e( 'Please avoid using an existing author&#8217;s name as the blog profile ID. Fediverse platforms might use caching and this could break the functionality completely.', 'activitypub' ); ?>
193 </strong>
194 </p>
195 <?php
196 }
197
198 /**
199 * Description field callback.
200 */
201 public static function description_callback() {
202 ?>
203 <label for="activitypub_blog_description">
204 <textarea
205 class="blog-user-description large-text"
206 rows="5"
207 name="activitypub_blog_description"
208 id="activitypub_blog_description"
209 placeholder="<?php echo \esc_attr( \get_bloginfo( 'description' ) ); ?>"
210 ><?php echo \esc_textarea( \get_option( 'activitypub_blog_description' ) ); ?></textarea>
211 </label>
212 <p class="description">
213 <?php \esc_html_e( 'By default the ActivityPub plugin uses the WordPress tagline as a description for the blog profile.', 'activitypub' ); ?>
214 </p>
215 <?php
216 }
217
218 /**
219 * Notifications field callback.
220 */
221 public static function notifications_callback() {
222 ?>
223 <fieldset id="activitypub-notifications">
224 <p>
225 <label>
226 <input type="checkbox" name="activitypub_blog_user_mailer_new_follower" id="activitypub_blog_user_mailer_new_follower" value="1" <?php \checked( '1', \get_option( 'activitypub_blog_user_mailer_new_follower', '1' ) ); ?> />
227 <?php \esc_html_e( 'New Followers', 'activitypub' ); ?>
228 </label>
229 </p>
230 <p>
231 <label>
232 <input type="checkbox" name="activitypub_blog_user_mailer_new_dm" id="activitypub_blog_user_mailer_new_dm" value="1" <?php \checked( '1', \get_option( 'activitypub_blog_user_mailer_new_dm', '1' ) ); ?> />
233 <?php \esc_html_e( 'Direct Messages', 'activitypub' ); ?>
234 </label>
235 </p>
236 <p>
237 <label>
238 <input type="checkbox" name="activitypub_blog_user_mailer_new_mention" id="activitypub_blog_user_mailer_new_mention" value="1" <?php \checked( '1', \get_option( 'activitypub_blog_user_mailer_new_mention', '1' ) ); ?> />
239 <?php \esc_html_e( 'New Mentions', 'activitypub' ); ?>
240 </label>
241 </p>
242 <p>
243 <label>
244 <input type="checkbox" name="activitypub_mailer_annual_report" id="activitypub_mailer_annual_report" value="1" <?php \checked( '1', \get_option( 'activitypub_mailer_annual_report', '1' ) ); ?> />
245 <?php \esc_html_e( 'Annual Report', 'activitypub' ); ?>
246 </label>
247 </p>
248 <p>
249 <label>
250 <input type="checkbox" name="activitypub_mailer_monthly_report" id="activitypub_mailer_monthly_report" value="1" <?php \checked( '1', \get_option( 'activitypub_mailer_monthly_report', '1' ) ); ?> />
251 <?php \esc_html_e( 'Monthly Report', 'activitypub' ); ?>
252 </label>
253 </p>
254 </fieldset>
255 <?php
256 }
257
258 /**
259 * Extra fields callback.
260 */
261 public static function extra_fields_callback() {
262 ?>
263 <p class="description">
264 <?php \esc_html_e( 'Your homepage, social profiles, pronouns, age, anything you want.', 'activitypub' ); ?>
265 </p>
266
267 <table class="widefat striped activitypub-extra-fields" role="presentation" style="margin: 15px 0;">
268 <?php
269 $extra_fields = Extra_Fields::get_actor_fields( Actors::BLOG_USER_ID );
270
271 if ( empty( $extra_fields ) ) :
272 ?>
273 <tr>
274 <td colspan="3">
275 <?php \esc_html_e( 'No extra fields found.', 'activitypub' ); ?>
276 </td>
277 </tr>
278 <?php
279 endif;
280
281 foreach ( $extra_fields as $extra_field ) :
282 ?>
283 <tr>
284 <td><?php echo \esc_html( $extra_field->post_title ); ?></td>
285 <td><?php echo \wp_kses_post( \get_the_excerpt( $extra_field ) ); ?></td>
286 <td>
287 <a href="<?php echo \esc_url( \get_edit_post_link( $extra_field->ID ) ); ?>" class="button">
288 <?php \esc_html_e( 'Edit', 'activitypub' ); ?>
289 </a>
290 </td>
291 </tr>
292 <?php endforeach; ?>
293 </table>
294
295 <p class="extra-fields-nav">
296 <a href="<?php echo \esc_url( \admin_url( '/post-new.php?post_type=ap_extrafield_blog' ) ); ?>" class="button">
297 <?php \esc_html_e( 'Add new', 'activitypub' ); ?>
298 </a>
299 <a href="<?php echo \esc_url( \admin_url( '/edit.php?post_type=ap_extrafield_blog' ) ); ?>">
300 <?php \esc_html_e( 'Manage all', 'activitypub' ); ?>
301 </a>
302 </p>
303 <?php
304 }
305
306 /**
307 * Also Known As field callback.
308 */
309 public static function also_known_as_callback() {
310 $also_known_as = \get_option( 'activitypub_blog_user_also_known_as' );
311 ?>
312 <label for="activitypub_blog_user_also_known_as">
313 <textarea
314 class="large-text"
315 id="activitypub_blog_user_also_known_as"
316 name="activitypub_blog_user_also_known_as"
317 rows="5"
318 ><?php echo \esc_textarea( \implode( PHP_EOL, (array) $also_known_as ) ); ?></textarea>
319 </label>
320 <p class="description">
321 <?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’t affect anything on its own. The migration itself is initiated from your old account.', 'activitypub' ); ?>
322 </p>
323 <p class="description">
324 <?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' ) ); ?>
325 </p>
326 <?php
327 }
328
329 /**
330 * Hide Social Graph field callback.
331 */
332 public static function hide_followers_callback() {
333 ?>
334 <label>
335 <input type="checkbox" name="activitypub_hide_social_graph" id="activitypub_hide_social_graph" value="1" <?php \checked( '1', \get_option( 'activitypub_hide_social_graph', '0' ) ); ?> />
336 <?php \esc_html_e( 'Hide Followers and Following on Profile', 'activitypub' ); ?>
337 </label>
338 <p class="description">
339 <?php \esc_html_e( 'People you follow will still see that you follow them.', 'activitypub' ); ?>
340 </p>
341 <?php
342 }
343 }
344