Skip to content

Commit 47e4c5a

Browse files
pfefferleobenland
andauthored
Onboarding: Improve troubleshooting UI (#1546)
* Onboarding: Improve troubleshooting UI * Add changelog * Fix phpcs issues * Update includes/wp-admin/class-welcome-fields.php Co-authored-by: Konstantin Obenland <[email protected]> * use admin notice hook and place to show troubleshoot * remove old tests --------- Co-authored-by: Konstantin Obenland <[email protected]>
1 parent d78a431 commit 47e4c5a

File tree

6 files changed

+119
-55
lines changed

6 files changed

+119
-55
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Significance: minor
2+
Type: changed
3+
4+
Improve the troubleshooting UI and show Site-Health stats in ActivityPub settings.

assets/css/activitypub-admin.css

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,3 +241,24 @@ input.blog-user-identifier {
241241
content: '\f335';
242242
font-size: 20px;
243243
}
244+
245+
.activitypub-notice .count {
246+
display: inline-block;
247+
vertical-align: top;
248+
box-sizing: border-box;
249+
margin: 1px 0 -1px 2px;
250+
padding: 0 5px;
251+
min-width: 18px;
252+
height: 18px;
253+
border-radius: 9px;
254+
background-color: #dba617;
255+
color: #fff;
256+
font-size: 11px;
257+
line-height: 1.6;
258+
text-align: center;
259+
z-index: 26;
260+
}
261+
262+
.activitypub-notice .dashicons-warning {
263+
color: #dba617;
264+
}

includes/wp-admin/class-admin.php

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,6 @@ public static function init() {
6666
* Display admin menu notices about configuration problems or conflicts.
6767
*/
6868
public static function admin_notices() {
69-
$permalink_structure = \get_option( 'permalink_structure' );
70-
if ( empty( $permalink_structure ) ) {
71-
$admin_notice = sprintf(
72-
/* translators: %s: Permalink settings URL. */
73-
\__( 'ActivityPub needs SEO-friendly URLs to work properly. Please <a href="%s">update your permalink structure</a> to an option other than Plain.', 'activitypub' ),
74-
esc_url( admin_url( 'options-permalink.php' ) )
75-
);
76-
self::show_admin_notice( $admin_notice, 'error' );
77-
}
78-
7969
$current_screen = get_current_screen();
8070
if ( ! $current_screen ) {
8171
return;

includes/wp-admin/class-health-check.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,51 @@ public static function init() {
2929
\add_filter( 'debug_information', array( self::class, 'debug_information' ) );
3030
}
3131

32+
/**
33+
* Count critical and recommended results.
34+
*
35+
* @param string $type The type of results to count.
36+
*
37+
* @return array The number of critical and recommended results.
38+
*/
39+
public static function count_results( $type = 'all' ) {
40+
$tests = self::add_tests( array() );
41+
42+
// Count critical and recommended results.
43+
$good = 0;
44+
$critical = 0;
45+
$recommended = 0;
46+
47+
foreach ( $tests['direct'] as $test ) {
48+
// Run tests.
49+
$result = call_user_func( $test['test'] );
50+
51+
if ( 'critical' === $result['status'] ) {
52+
++$critical;
53+
}
54+
55+
if ( 'recommended' === $result['status'] ) {
56+
++$recommended;
57+
}
58+
59+
if ( 'good' === $result['status'] ) {
60+
++$good;
61+
}
62+
}
63+
64+
$results = array(
65+
'good' => $good,
66+
'critical' => $critical,
67+
'recommended' => $recommended,
68+
);
69+
70+
if ( 'all' === $type ) {
71+
return $results;
72+
}
73+
74+
return $results[ $type ];
75+
}
76+
3277
/**
3378
* Add tests to the Site Health Check.
3479
*

includes/wp-admin/class-welcome-fields.php

Lines changed: 49 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ class Welcome_Fields {
2121
* Initialize the welcome fields.
2222
*/
2323
public static function init() {
24-
add_action( 'load-settings_page_activitypub', array( self::class, 'register_welcome_fields' ) );
24+
\add_action( 'load-settings_page_activitypub', array( self::class, 'register_welcome_fields' ) );
25+
\add_action( 'load-settings_page_activitypub', array( self::class, 'add_admin_notices' ) );
2526
}
2627

2728
/**
@@ -61,13 +62,6 @@ public static function register_welcome_fields() {
6162
);
6263
}
6364

64-
\add_settings_section(
65-
'activitypub_troubleshooting',
66-
\__( 'Troubleshooting', 'activitypub' ),
67-
array( self::class, 'render_troubleshooting_section' ),
68-
'activitypub_welcome'
69-
);
70-
7165
if ( ACTIVITYPUB_SHOW_PLUGIN_RECOMMENDATIONS ) {
7266
\add_settings_section(
7367
'activitypub_recommended_plugins',
@@ -78,6 +72,24 @@ public static function register_welcome_fields() {
7872
}
7973
}
8074

75+
/**
76+
* Add Health Check errors as admin notices.
77+
*/
78+
public static function add_admin_notices() {
79+
// phpcs:ignore WordPress.Security.NonceVerification.Recommended
80+
if ( isset( $_GET['tab'] ) && 'welcome' !== $_GET['tab'] ) {
81+
return;
82+
}
83+
84+
if ( ! \get_user_meta( \get_current_user_id(), 'activitypub_show_welcome_tab', true ) ) {
85+
return;
86+
}
87+
88+
if ( Health_Check::count_results( 'critical' ) ) {
89+
\add_action( 'admin_notices', array( self::class, 'admin_notices' ) );
90+
}
91+
}
92+
8193
/**
8294
* Render welcome intro section.
8395
*/
@@ -193,23 +205,37 @@ public static function render_author_profile_section() {
193205
/**
194206
* Render troubleshooting section.
195207
*/
196-
public static function render_troubleshooting_section() {
208+
public static function admin_notices() {
209+
$results = Health_Check::count_results();
197210
?>
198-
<p>
199-
<?php
200-
echo wp_kses(
201-
\sprintf(
202-
/* translators: the placeholder is the Site Health URL */
203-
\__(
204-
'If you have problems using this plugin, please check the <a href="%s">Site Health</a> page to ensure that your site is compatible and/or use the "Help" tab (in the top right of the settings pages).',
205-
'activitypub'
211+
<div class="activitypub-notice notice notice-warning">
212+
<p>
213+
<span class="dashicons dashicons-warning"></span>
214+
<?php
215+
echo wp_kses(
216+
\sprintf(
217+
/* translators: the placeholders are the number of critical and recommended issues on the site. */
218+
\__(
219+
'<strong>Important:</strong> There are <span class="count">%1$d</span> critical and <span class="count">%2$d</span> recommended issues affecting your site&#8217;s compatibility with the fediverse. Please check the <a href="%3$s">Site Health</a> page to resolve these issues.',
220+
'activitypub'
221+
),
222+
$results['critical'],
223+
$results['recommended'],
224+
\esc_url( \admin_url( 'site-health.php' ) )
206225
),
207-
\esc_url( admin_url( 'site-health.php' ) )
208-
),
209-
'default'
210-
);
211-
?>
212-
</p>
226+
array(
227+
'strong' => array(),
228+
'span' => array(
229+
'class' => array(),
230+
),
231+
'a' => array(
232+
'href' => array(),
233+
),
234+
)
235+
);
236+
?>
237+
</p>
238+
</div>
213239
<?php
214240
}
215241

tests/includes/wp-admin/class-test-admin.php

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,4 @@ class Test_Admin extends \WP_UnitTestCase {
2020
public static function set_up_before_class() {
2121
\Activitypub\WP_Admin\Admin::init();
2222
}
23-
24-
/**
25-
* Test the admin notice for missing permalink structure.
26-
*/
27-
public function test_no_permalink_structure_has_errors() {
28-
\add_option( 'permalink_structure', '' );
29-
\do_action( 'admin_notices' );
30-
$this->expectOutputRegex( '/notice-error/' );
31-
32-
\delete_option( 'permalink_structure' );
33-
}
34-
35-
/**
36-
* Test there is no error notice when the permalink structure is set.
37-
*/
38-
public function test_has_permalink_structure_no_errors() {
39-
\add_option( 'permalink_structure', '/archives/%post_id%' );
40-
\do_action( 'admin_notices' );
41-
$this->expectOutputRegex( '/^((?!notice-error).)*$/s' );
42-
43-
\delete_option( 'permalink_structure' );
44-
}
4523
}

0 commit comments

Comments
 (0)