Fix the health check (#481)

* only test author urls if authors are enabled

* if authors are disabled use the blog user to test webfinger
This commit is contained in:
Matthias Pfefferle 2023-10-02 17:12:23 +02:00 committed by GitHub
parent 336f3e5a62
commit b7c0e011de
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -3,8 +3,10 @@ namespace Activitypub;
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;
/**
@ -25,10 +27,12 @@ class Health_Check {
}
public static function add_tests( $tests ) {
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' ),
@ -254,7 +258,14 @@ class Health_Check {
*/
public static function is_webfinger_endpoint_accessible() {
$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 ) ) {