From 913b60c7c7af445c65a4c033a9c42e29f0895f26 Mon Sep 17 00:00:00 2001 From: Matthias Pfefferle Date: Wed, 31 May 2023 08:45:14 +0200 Subject: [PATCH] Fix WebFinger resources for Blog-User and updated settings. --- includes/class-activitypub.php | 5 +++++ includes/class-webfinger.php | 4 ++-- includes/model/class-blog-user.php | 2 +- includes/model/class-user.php | 4 ++++ templates/settings.php | 13 ++++++++++-- templates/welcome.php | 33 ++++++++++++++++++++++++++---- 6 files changed, 52 insertions(+), 9 deletions(-) diff --git a/includes/class-activitypub.php b/includes/class-activitypub.php index 7e5ea2f..cd95fc7 100644 --- a/includes/class-activitypub.php +++ b/includes/class-activitypub.php @@ -245,6 +245,11 @@ class Activitypub { \flush_rewrite_rules(); } + /** + * Theme compatibility stuff + * + * @return void + */ public static function theme_compat() { $site_icon = get_theme_support( 'custom-logo' ); diff --git a/includes/class-webfinger.php b/includes/class-webfinger.php index 44a4a27..958f544 100644 --- a/includes/class-webfinger.php +++ b/includes/class-webfinger.php @@ -24,12 +24,12 @@ class Webfinger { return \get_webfinger_resource( $user_id, false ); } - $user = \get_user_by( 'id', $user_id ); + $user = User_Factory::get_by_id( $user_id ); if ( ! $user ) { return ''; } - return $user->user_login . '@' . \wp_parse_url( \home_url(), \PHP_URL_HOST ); + return $user->get_resource(); } /** diff --git a/includes/model/class-blog-user.php b/includes/model/class-blog-user.php index 492bf76..d703275 100644 --- a/includes/model/class-blog-user.php +++ b/includes/model/class-blog-user.php @@ -24,7 +24,7 @@ class Blog_User extends User { * * @param int $user_id The User-ID. */ - public function __construct( $user_id ) { + public function __construct( $user_id = null ) { add_filter( 'activitypub_json_author_array', array( $this, 'add_api_endpoints' ), 10, 2 ); } diff --git a/includes/model/class-user.php b/includes/model/class-user.php index 2cee714..8791a50 100644 --- a/includes/model/class-user.php +++ b/includes/model/class-user.php @@ -247,4 +247,8 @@ class User { return $array; } + + public function get_resource() { + return $this->get_username() . '@' . \wp_parse_url( \home_url(), \PHP_URL_HOST ); + } } diff --git a/templates/settings.php b/templates/settings.php index 5bc9c90..6d8a0cb 100644 --- a/templates/settings.php +++ b/templates/settings.php @@ -42,10 +42,19 @@
- +

- + Customizer.', 'activitypub' ), + \esc_url_raw( \admin_url( 'customize.php' ) ) + ), + 'default' + ); + ?>

diff --git a/templates/welcome.php b/templates/welcome.php index cb4d05f..acf986d 100644 --- a/templates/welcome.php +++ b/templates/welcome.php @@ -13,29 +13,54 @@

+

%1$s or the URL %2$s. Users who can not access this settings page will find their username on the Edit Profile page.', + 'People can follow your Blog by using the username %1$s or the URL %2$s. This Blog-User will federate all posts written on your Blog, regardless of the User who posted it. You can customize the Blog-User on the Settings Page.', 'activitypub' ), - \esc_attr( \Activitypub\get_webfinger_resource( wp_get_current_user()->ID ) ), - \esc_url_raw( \get_author_posts_url( wp_get_current_user()->ID ) ), + \esc_attr( $blog_user->get_resource() ), + \esc_url_raw( $blog_user->get_url() ), + \esc_url_raw( \admin_url( '/options-general.php?page=activitypub&tab=settings' ) ) + ), + 'default' + ); + ?> +

+

+

+ ID ); + echo wp_kses( + \sprintf( + // translators: + \__( + 'People can also follow you by using your Username %1$s or your Author-URL %2$s. Users who can not access this settings page will find their username on the Edit Profile page.', + 'activitypub' + ), + \esc_attr( $user->get_resource() ), + \esc_url_raw( $user->get_url() ), \esc_url_raw( \admin_url( 'profile.php#activitypub' ) ) ), 'default' ); ?>

+

Site Health to ensure that your site is compatible and/or use the "Help" tab (in the top right of the settings pages).', 'activitypub' ), + \__( + 'If you have problems using this plugin, please check the Site Health to ensure that your site is compatible and/or use the "Help" tab (in the top right of the settings pages).', + 'activitypub' + ), \esc_url_raw( admin_url( 'site-health.php' ) ) ), 'default'