Skip to content

Commit b49cc53

Browse files
committed
optimized health check
1 parent 5ba691e commit b49cc53

File tree

1 file changed

+37
-4
lines changed

1 file changed

+37
-4
lines changed

includes/class-health-check.php

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,15 @@ public static function add_tests( $tests ) {
2727

2828
public static function test_profile_url() {
2929
$result = array(
30-
'label' => \__( 'Profile URL accessible', 'activitypub' ),
30+
'label' => \__( 'Author URL accessible', 'activitypub' ),
3131
'status' => 'good',
3232
'badge' => array(
3333
'label' => \__( 'ActivityPub', 'activitypub' ),
3434
'color' => 'green',
3535
),
3636
'description' => \sprintf(
3737
'<p>%s</p>',
38-
\__( 'Your profile URL is accessible and do not redirect to the home page.', 'activitypub' )
38+
\__( 'Your author URL is accessible and supports the required "Accept" header.', 'activitypub' )
3939
),
4040
'actions' => '',
4141
'test' => 'test_profile_url',
@@ -48,7 +48,7 @@ public static function test_profile_url() {
4848
$result['label'] = \__( 'Profile URL is not accessible', 'activitypub' );
4949
$result['description'] = \sprintf(
5050
'<p>%s</p>',
51-
\__( 'Authorization Headers are being blocked by your hosting provider. This will cause IndieAuth to fail.', 'activitypub' )
51+
\__( 'Your author URL is not accessible and/or does not return valid JSON. Please check if the author URL is accessible and does not redirect to another page (often done by SEO plugins).', 'activitypub' )
5252
);
5353
}
5454

@@ -58,9 +58,10 @@ public static function test_profile_url() {
5858
public static function is_profile_url_accessible() {
5959
$user = \wp_get_current_user();
6060
$author_url = \get_author_posts_url( $user->ID );
61+
$reference_author_url = self::get_author_posts_url( $user->ID, $user->user_nicename );
6162

6263
// check for "author" in URL
63-
if ( false === \strpos( $author_url, 'author' ) ) {
64+
if ( $author_url !== $reference_author_url ) {
6465
return false;
6566
}
6667

@@ -80,4 +81,36 @@ public static function is_profile_url_accessible() {
8081

8182
return true;
8283
}
84+
85+
/**
86+
* Retrieve the URL to the author page for the user with the ID provided.
87+
*
88+
* @global WP_Rewrite $wp_rewrite WordPress rewrite component.
89+
*
90+
* @param int $author_id Author ID.
91+
* @param string $author_nicename Optional. The author's nicename (slug). Default empty.
92+
*
93+
* @return string The URL to the author's page.
94+
*/
95+
public static function get_author_posts_url( $author_id, $author_nicename = '' ) {
96+
global $wp_rewrite;
97+
$auth_id = (int) $author_id;
98+
$link = $wp_rewrite->get_author_permastruct();
99+
100+
if ( empty( $link ) ) {
101+
$file = home_url( '/' );
102+
$link = $file . '?author=' . $auth_id;
103+
} else {
104+
if ( '' === $author_nicename ) {
105+
$user = get_userdata( $author_id );
106+
if ( ! empty( $user->user_nicename ) ) {
107+
$author_nicename = $user->user_nicename;
108+
}
109+
}
110+
$link = str_replace( '%author%', $author_nicename, $link );
111+
$link = home_url( user_trailingslashit( $link ) );
112+
}
113+
114+
return $link;
115+
}
83116
}

0 commit comments

Comments
 (0)