From d6ff82b33706dd56bfd31efc17ad58347cb837c3 Mon Sep 17 00:00:00 2001 From: Matt Wiebe Date: Tue, 15 Aug 2023 18:22:58 -0500 Subject: [PATCH] adds a `get_webfinger_identifier` method (#397) also `get_at_url` needed an update for the Blog User, who would throw an error otherwise --- includes/model/class-blog-user.php | 9 +++++++++ includes/model/class-user.php | 14 ++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/includes/model/class-blog-user.php b/includes/model/class-blog-user.php index 471f2c5..3a1ae07 100644 --- a/includes/model/class-blog-user.php +++ b/includes/model/class-blog-user.php @@ -77,6 +77,15 @@ class Blog_User extends User { return \esc_url( \trailingslashit( get_home_url() ) . '@' . $this->get_preferred_username() ); } + /** + * Returns the User-URL with @-Prefix for the username. + * + * @return string The User-URL with @-Prefix for the username. + */ + public function get_at_url() { + return \esc_url( \trailingslashit( get_home_url() ) . '@' . $this->get_preferred_username() ); + } + /** * Generate a default Username. * diff --git a/includes/model/class-user.php b/includes/model/class-user.php index 63ec86f..7fa7519 100644 --- a/includes/model/class-user.php +++ b/includes/model/class-user.php @@ -98,10 +98,24 @@ class User extends Actor { return \esc_url( \get_author_posts_url( $this->_id ) ); } + /** + * Returns the User-URL with @-Prefix for the username. + * + * @return string The User-URL with @-Prefix for the username. + */ public function get_at_url() { return \esc_url( \trailingslashit( get_home_url() ) . '@' . $this->get_username() ); } + /** + * Returns a user@domain type of identifier for the user. + * + * @return string The Webfinger-Identifier. + */ + public function get_webfinger_identifier() { + return sprintf( '%s@%s', $this->get_preferred_username(), wp_parse_url( home_url(), PHP_URL_HOST ) ); + } + public function get_preferred_username() { return \esc_attr( \get_the_author_meta( 'login', $this->_id ) ); }