PluginProbe
ActivityPub / 7.0.0
ActivityPub v7.0.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-welcome-fields.php

class-welcome-fields.php in ActivityPub 7.0.0, at includes/wp-admin/class-welcome-fields.php

422 lines 15.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * ActivityPub Welcome Fields Class.
4 *
5 * @package Activitypub
6 */
7
8 namespace Activitypub\WP_Admin;
9
10 use function Activitypub\user_can_activitypub;
11
12 /**
13 * Class Welcome_Fields.
14 */
15 class Welcome_Fields {
16 /**
17 * Initialize the welcome fields.
18 */
19 public static function init() {
20 \add_action( 'load-settings_page_activitypub', array( self::class, 'register_welcome_fields' ) );
21
22 \add_action( 'add_option_activitypub_checklist_health_check_issues', array( self::class, 'resolve_checklist' ) );
23 \add_action( 'update_option_activitypub_checklist_health_check_issues', array( self::class, 'resolve_checklist' ) );
24 \add_action( 'add_option_activitypub_checklist_fediverse_intro_visited', array( self::class, 'resolve_checklist' ) );
25 \add_action( 'update_option_activitypub_checklist_fediverse_intro_visited', array( self::class, 'resolve_checklist' ) );
26 \add_action( 'add_option_activitypub_checklist_settings_visited', array( self::class, 'resolve_checklist' ) );
27 \add_action( 'update_option_activitypub_checklist_settings_visited', array( self::class, 'resolve_checklist' ) );
28 \add_action( 'add_option_activitypub_checklist_profile_setup_visited', array( self::class, 'resolve_checklist' ) );
29 \add_action( 'update_option_activitypub_checklist_profile_setup_visited', array( self::class, 'resolve_checklist' ) );
30 \add_action( 'add_option_activitypub_checklist_blocks_visited', array( self::class, 'resolve_checklist' ) );
31 \add_action( 'update_option_activitypub_checklist_blocks_visited', array( self::class, 'resolve_checklist' ) );
32 }
33
34 /**
35 * Register welcome fields.
36 */
37 public static function register_welcome_fields() {
38 \add_settings_section(
39 'activitypub_welcome_header',
40 '',
41 array( self::class, 'render_welcome_header_section' ),
42 'activitypub_welcome'
43 );
44
45 \add_settings_section(
46 'activitypub_onboarding_steps',
47 '',
48 array( self::class, 'render_onboarding_steps_section' ),
49 'activitypub_welcome'
50 );
51
52 \add_settings_section(
53 'activitypub_welcome_footer',
54 '',
55 array( self::class, 'render_welcome_footer_section' ),
56 'activitypub_welcome'
57 );
58
59 \add_action( 'activitypub_onboarding_steps', array( self::class, 'render_step_plugin_installed' ), 10 );
60 \add_action( 'activitypub_onboarding_steps', array( self::class, 'render_step_site_health' ), 20 );
61 \add_action( 'activitypub_onboarding_steps', array( self::class, 'render_step_fediverse_intro' ), 30 );
62 \add_action( 'activitypub_onboarding_steps', array( self::class, 'render_step_profile_mode' ), 40 );
63 \add_action( 'activitypub_onboarding_steps', array( self::class, 'render_step_profile_setup' ), 50 );
64 \add_action( 'activitypub_onboarding_steps', array( self::class, 'render_step_features' ), 60 );
65
66 /*
67 * Keep track of health check issues. This is used to determine if the site health step is complete.
68 *
69 * This needs to happen after onboarding steps were registered, so that we can compare the number of completed
70 * steps with the number of registered steps.
71 */
72 \update_option( 'activitypub_checklist_health_check_issues', (string) Health_Check::count_results( 'critical' ) );
73 }
74
75 /**
76 * Render welcome header section.
77 */
78 public static function render_welcome_header_section() {
79 $completed_steps = self::get_completed_steps_count();
80 $total_steps = self::get_total_steps_count();
81 $progress_percentage = \min( 100, \round( ( $completed_steps / $total_steps ) * 100 ) );
82 ?>
83 <div id="activitypub-welcome-checklist" class="activitypub-welcome-container">
84 <div class="activitypub-welcome-header">
85 <div class="activitypub-progress-circle">
86 <div class="activitypub-progress-circle-content">
87 <span><?php echo \esc_html( $completed_steps ); ?>/<?php echo \esc_html( $total_steps ); ?></span>
88 </div>
89 <svg class="activitypub-progress-ring" width="120" height="120">
90 <circle class="activitypub-progress-ring-bg" cx="60" cy="60" r="54" />
91 <circle class="activitypub-progress-ring-circle" cx="60" cy="60" r="54"
92 stroke-dasharray="339.292"
93 stroke-dashoffset="<?php echo \esc_attr( 339.292 - ( 339.292 * $progress_percentage / 100 ) ); ?>" />
94 </svg>
95 </div>
96 <h2 class="activitypub-welcome-title"><?php \esc_html_e( 'Welcome to the Fediverse!', 'activitypub' ); ?></h2>
97 <p class="activitypub-welcome-subtitle"><?php \esc_html_e( 'Get connected in just a few steps.', 'activitypub' ); ?></p>
98 </div>
99 <?php
100 }
101
102 /**
103 * Get the count of completed steps.
104 */
105 private static function get_completed_steps_count() {
106 $count = 1; // Plugin is already installed.
107
108 // We're looking for 0 issues.
109 if ( self::has_step( 'site_health' ) && '0' === \get_option( 'activitypub_checklist_health_check_issues', (string) Health_Check::count_results( 'critical' ) ) ) {
110 ++$count;
111 }
112
113 // Check other completed steps.
114 if ( self::has_step( 'fediverse_intro' ) && '1' === \get_option( 'activitypub_checklist_fediverse_intro_visited' ) ) {
115 ++$count;
116 }
117
118 if ( self::has_step( 'profile_mode' ) && '1' === \get_option( 'activitypub_checklist_settings_visited' ) ) {
119 ++$count;
120 }
121
122 if ( self::has_step( 'profile_setup' ) && '1' === \get_option( 'activitypub_checklist_profile_setup_visited' ) ) {
123 ++$count;
124 }
125
126 if ( self::has_step( 'features' ) && '1' === \get_option( 'activitypub_checklist_blocks_visited' ) ) {
127 ++$count;
128 }
129
130 return $count;
131 }
132
133 /**
134 * Get the total number of steps.
135 */
136 private static function get_total_steps_count() {
137 global $wp_filter;
138
139 $count = 0;
140
141 if ( isset( $wp_filter['activitypub_onboarding_steps'] ) ) {
142 $count = \count( $wp_filter['activitypub_onboarding_steps']->callbacks );
143 }
144
145 return $count;
146 }
147
148 /**
149 * Get the next incomplete step.
150 */
151 private static function get_next_incomplete_step() {
152 if ( self::has_step( 'site_health' ) && '0' !== \get_option( 'activitypub_checklist_health_check_issues', (string) Health_Check::count_results( 'critical' ) ) ) {
153 return 'site_health';
154 }
155
156 if ( self::has_step( 'fediverse_intro' ) && ! \get_option( 'activitypub_checklist_fediverse_intro_visited', false ) ) {
157 return 'fediverse_intro';
158 }
159
160 if ( self::has_step( 'profile_mode' ) && ! \get_option( 'activitypub_checklist_settings_visited', false ) ) {
161 return 'profile_mode';
162 }
163
164 if ( self::has_step( 'profile_setup' ) && ! \get_option( 'activitypub_checklist_profile_setup_visited', false ) ) {
165 return 'profile_setup';
166 }
167
168 if ( self::has_step( 'features' ) && ! \get_option( 'activitypub_checklist_blocks_visited', false ) ) {
169 return 'features';
170 }
171
172 return '';
173 }
174
175 /**
176 * Check if a step exists.
177 *
178 * @param string $step Step slug.
179 * @return bool
180 */
181 private static function has_step( $step ) {
182 return \has_action( 'activitypub_onboarding_steps', array( self::class, 'render_step_' . $step ) );
183 }
184
185 /**
186 * Render onboarding steps section.
187 */
188 public static function render_onboarding_steps_section() {
189 ?>
190 <div class="activitypub-onboarding-steps">
191 <?php
192 \do_action( 'activitypub_onboarding_steps' );
193 ?>
194 </div>
195 <?php
196 }
197
198 /**
199 * Render plugin installed step.
200 */
201 public static function render_step_plugin_installed() {
202 ?>
203 <div class="activitypub-onboarding-step activitypub-step-completed">
204 <div class="step-indicator">
205 <span class="step-icon dashicons dashicons-yes"></span>
206 </div>
207 <div class="step-content">
208 <div class="step-text">
209 <h3><?php \esc_html_e( 'Plugin installed', 'activitypub' ); ?></h3>
210 </div>
211 </div>
212 </div>
213 <?php
214 }
215
216 /**
217 * Render site health step.
218 */
219 public static function render_step_site_health() {
220 $health_issues = Health_Check::count_results();
221 $total_issues = $health_issues['critical'] + $health_issues['recommended'];
222 $checked = '0' === \get_option( 'activitypub_checklist_health_check_issues', (string) $health_issues['critical'] );
223 $step_class = $checked ? 'activitypub-step-completed' : '';
224 $next_step = self::get_next_incomplete_step();
225 $button_class = ( 'site_health' === $next_step ) ? 'button-primary' : 'button-secondary';
226 ?>
227 <div class="activitypub-onboarding-step <?php echo \esc_attr( $step_class ); ?>">
228 <div class="step-indicator">
229 <?php if ( $checked ) : ?>
230 <span class="step-icon dashicons dashicons-yes"></span>
231 <?php else : ?>
232 <span class="step-icon dashicons dashicons-warning"></span>
233 <?php endif; ?>
234 </div>
235 <div class="step-content">
236 <div class="step-text">
237 <h3><?php \esc_html_e( 'Check your site&#8217;s health', 'activitypub' ); ?></h3>
238 <p>
239 <?php
240 echo \esc_html(
241 \sprintf(
242 /* translators: %d: Number of issues. */
243 \_n( '%d issue needs your attention.', '%d issues need your attention.', $total_issues, 'activitypub' ),
244 $total_issues
245 )
246 );
247 ?>
248 </p>
249 </div>
250 <div class="step-action">
251 <a href="<?php echo \esc_url( \admin_url( 'site-health.php' ) ); ?>" class="button <?php echo \esc_attr( $button_class ); ?>">
252 <?php \esc_html_e( 'Review issues', 'activitypub' ); ?>
253 </a>
254 </div>
255 </div>
256 </div>
257 <?php
258 }
259
260 /**
261 * Render the Fediverse-Intro step.
262 */
263 public static function render_step_fediverse_intro() {
264 $checked = '1' === \get_option( 'activitypub_checklist_fediverse_intro_visited', false );
265 $step_class = $checked ? 'activitypub-step-completed' : '';
266 $next_step = self::get_next_incomplete_step();
267 $button_class = ( 'fediverse_intro' === $next_step ) ? 'button-primary' : 'button-secondary';
268 ?>
269 <div class="activitypub-onboarding-step <?php echo \esc_attr( $step_class ); ?>">
270 <div class="step-indicator">
271 <?php if ( $checked ) : ?>
272 <span class="step-icon dashicons dashicons-yes"></span>
273 <?php else : ?>
274 <span class="step-icon dashicons dashicons-video-alt3"></span>
275 <?php endif; ?>
276 </div>
277 <div class="step-content">
278 <div class="step-text">
279 <h3><?php \esc_html_e( 'New to the Fediverse? Start Here', 'activitypub' ); ?></h3>
280 <p><?php \esc_html_e( 'Learn what the Fediverse is and why it matters.', 'activitypub' ); ?></p>
281 </div>
282 <div class="step-action">
283 <a href="<?php echo \esc_url( \admin_url( 'options-general.php?page=activitypub&help-tab=getting-started#tab-link-getting-started' ) ); ?>" class="button <?php echo \esc_attr( $button_class ); ?>">
284 <?php \esc_html_e( 'View intro', 'activitypub' ); ?>
285 </a>
286 </div>
287 </div>
288 </div>
289 <?php
290 }
291
292 /**
293 * Render the Profile Mode step.
294 */
295 public static function render_step_profile_mode() {
296 $checked = '1' === \get_option( 'activitypub_checklist_settings_visited', false );
297 $step_class = $checked ? 'activitypub-step-completed' : '';
298 $next_step = self::get_next_incomplete_step();
299 $button_class = ( 'profile_mode' === $next_step ) ? 'button-primary' : 'button-secondary';
300 ?>
301 <div class="activitypub-onboarding-step <?php echo \esc_attr( $step_class ); ?>">
302 <div class="step-indicator">
303 <?php if ( $checked ) : ?>
304 <span class="step-icon dashicons dashicons-yes"></span>
305 <?php else : ?>
306 <span class="step-icon dashicons dashicons-groups"></span>
307 <?php endif; ?>
308 </div>
309 <div class="step-content">
310 <div class="step-text">
311 <h3><?php \esc_html_e( 'Select how you want to share', 'activitypub' ); ?></h3>
312 <p><?php \esc_html_e( 'Pick your preferred user mode for connecting with others.', 'activitypub' ); ?></p>
313 </div>
314 <div class="step-action">
315 <a href="<?php echo \esc_url( \admin_url( 'options-general.php?page=activitypub&tab=settings' ) ); ?>" class="button <?php echo \esc_attr( $button_class ); ?>">
316 <?php \esc_html_e( 'Choose mode', 'activitypub' ); ?>
317 </a>
318 </div>
319 </div>
320 </div>
321 <?php
322 }
323
324 /**
325 * Render the Profile Setup step.
326 */
327 public static function render_step_profile_setup() {
328 $user_can_activitypub = user_can_activitypub( \get_current_user_id() );
329 $checked = '1' === \get_option( 'activitypub_checklist_profile_setup_visited', false );
330 $step_class = $checked ? 'activitypub-step-completed' : '';
331 $next_step = self::get_next_incomplete_step();
332 $button_class = ( 'profile_setup' === $next_step ) ? 'button-primary' : 'button-secondary';
333 ?>
334 <div class="activitypub-onboarding-step <?php echo \esc_attr( $step_class ); ?>">
335 <div class="step-indicator">
336 <?php if ( $checked ) : ?>
337 <span class="step-icon dashicons dashicons-yes"></span>
338 <?php else : ?>
339 <span class="step-icon dashicons dashicons-admin-users"></span>
340 <?php endif; ?>
341 </div>
342 <div class="step-content">
343 <div class="step-text">
344 <h3><?php \esc_html_e( 'Set up your public profile', 'activitypub' ); ?></h3>
345 <p><?php \esc_html_e( 'Configure your display name and how you appear to others.', 'activitypub' ); ?></p>
346 </div>
347 <div class="step-action">
348 <?php if ( true === $user_can_activitypub ) : ?>
349 <a href="<?php echo \esc_url( \admin_url( '/profile.php#activitypub' ) ); ?>" class="button <?php echo \esc_attr( $button_class ); ?>">
350 <?php \esc_html_e( 'Edit profile', 'activitypub' ); ?>
351 </a>
352 <?php elseif ( ACTIVITYPUB_BLOG_MODE === \get_option( 'activitypub_actor_mode' ) ) : ?>
353 <a href="<?php echo \esc_url( \admin_url( '/options-general.php?page=activitypub&tab=blog-profile' ) ); ?>" class="button <?php echo \esc_attr( $button_class ); ?>">
354 <?php \esc_html_e( 'Edit profile', 'activitypub' ); ?>
355 </a>
356 <?php else : ?>
357 <button class="button <?php echo \esc_attr( $button_class ); ?>" disabled>
358 <?php \esc_html_e( 'Edit profile', 'activitypub' ); ?>
359 </button>
360 <?php endif; ?>
361 </div>
362 </div>
363 </div>
364 <?php
365 }
366
367 /**
368 * Render the Features step.
369 */
370 public static function render_step_features() {
371 $checked = '1' === \get_option( 'activitypub_checklist_blocks_visited', false );
372 $step_class = $checked ? 'activitypub-step-completed' : '';
373 $next_step = self::get_next_incomplete_step();
374 $button_class = ( 'features' === $next_step ) ? 'button-primary' : 'button-secondary';
375 ?>
376 <div class="activitypub-onboarding-step <?php echo \esc_attr( $step_class ); ?>">
377 <div class="step-indicator">
378 <?php if ( $checked ) : ?>
379 <span class="step-icon dashicons dashicons-yes"></span>
380 <?php else : ?>
381 <span class="step-icon dashicons dashicons-info"></span>
382 <?php endif; ?>
383 </div>
384 <div class="step-content">
385 <div class="step-text">
386 <h3><?php \esc_html_e( 'Learn more about Fediverse features', 'activitypub' ); ?></h3>
387 <p><?php \esc_html_e( 'Discover blocks, privacy, and more.', 'activitypub' ); ?></p>
388 </div>
389 <div class="step-action">
390 <a href="<?php echo \esc_url( \admin_url( 'options-general.php?page=activitypub&help-tab=editor-blocks#tab-link-editor-blocks' ) ); ?>" class="button <?php echo \esc_attr( $button_class ); ?>">
391 <?php \esc_html_e( 'Explore features', 'activitypub' ); ?>
392 </a>
393 </div>
394 </div>
395 </div>
396 <?php
397 }
398
399 /**
400 * Render welcome footer section.
401 */
402 public static function render_welcome_footer_section() {
403 ?>
404 </div><!-- closing welcome-container div -->
405 <div class="activitypub-welcome-footer">
406 <a href="<?php echo \esc_url( \admin_url( 'options-general.php?page=activitypub&welcome=0' ) ); ?>" class="skip-steps-link">
407 <?php \esc_html_e( 'Skip these steps', 'activitypub' ); ?>
408 </a>
409 </div>
410 <?php
411 }
412
413 /**
414 * Resolve the welcome checklist.
415 */
416 public static function resolve_checklist() {
417 if ( self::get_total_steps_count() === self::get_completed_steps_count() ) {
418 \update_user_meta( \get_current_user_id(), 'activitypub_show_welcome_tab', 0 );
419 }
420 }
421 }
422