Skip to content

Commit

Permalink
Fix the health check (#481)
Browse files Browse the repository at this point in the history
* only test author urls if authors are enabled

* if authors are disabled use the blog user to test webfinger
  • Loading branch information
pfefferle authored Oct 2, 2023
1 parent 336f3e5 commit b7c0e01
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions includes/class-health-check.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@

use WP_Error;
use Activitypub\Webfinger;
use Activitypub\Collection\Users;

use function Activitypub\get_plugin_version;
use function Activitypub\is_user_type_disabled;
use function Activitypub\get_webfinger_resource;

/**
Expand All @@ -25,10 +27,12 @@ public static function init() {
}

public static function add_tests( $tests ) {
$tests['direct']['activitypub_test_author_url'] = array(
'label' => \__( 'Author URL test', 'activitypub' ),
'test' => array( self::class, 'test_author_url' ),
);
if ( ! is_user_type_disabled( 'user' ) ) {
$tests['direct']['activitypub_test_author_url'] = array(
'label' => \__( 'Author URL test', 'activitypub' ),
'test' => array( self::class, 'test_author_url' ),
);
}

$tests['direct']['activitypub_test_webfinger'] = array(
'label' => __( 'WebFinger Test', 'activitypub' ),
Expand Down Expand Up @@ -253,8 +257,15 @@ public static function is_author_url_accessible() {
* @return boolean|WP_Error
*/
public static function is_webfinger_endpoint_accessible() {
$user = \wp_get_current_user();
$account = get_webfinger_resource( $user->ID );
$user = \wp_get_current_user();

if ( ! is_user_type_disabled( 'blog' ) ) {
$account = get_webfinger_resource( $user->ID );
} elseif ( ! is_user_type_disabled( 'user' ) ) {
$account = get_webfinger_resource( Users::BLOG_USER_ID );
} else {
$account = '';
}

$url = Webfinger::resolve( $account );
if ( \is_wp_error( $url ) ) {
Expand Down

0 comments on commit b7c0e01

Please sign in to comment.