From 002d4e7981d00e7dd12be082dae1e3abc0c4b426 Mon Sep 17 00:00:00 2001 From: Matthias Pfefferle Date: Tue, 11 Jul 2023 14:34:11 +0200 Subject: [PATCH] refactoring --- includes/class-http.php | 13 +++++++++++++ includes/class-migration.php | 22 +++++++++++++++++++++- includes/model/class-blog-user.php | 26 ++++++++++++++++++++++++-- 3 files changed, 58 insertions(+), 3 deletions(-) diff --git a/includes/class-http.php b/includes/class-http.php index dd19f9b3..11571379 100644 --- a/includes/class-http.php +++ b/includes/class-http.php @@ -25,6 +25,12 @@ class Http { $signature = Signature::generate_signature( $user_id, 'post', $url, $date, $digest ); $wp_version = \get_bloginfo( 'version' ); + + /** + * Filter the HTTP headers user agent. + * + * @param string $user_agent The user agent string. + */ $user_agent = \apply_filters( 'http_headers_useragent', 'WordPress/' . $wp_version . '; ' . \get_bloginfo( 'url' ) ); $args = array( 'timeout' => 100, @@ -66,7 +72,14 @@ class Http { $signature = Signature::generate_signature( Users::APPLICATION_USER_ID, 'get', $url, $date ); $wp_version = \get_bloginfo( 'version' ); + + /** + * Filter the HTTP headers user agent. + * + * @param string $user_agent The user agent string. + */ $user_agent = \apply_filters( 'http_headers_useragent', 'WordPress/' . $wp_version . '; ' . \get_bloginfo( 'url' ) ); + $args = array( 'timeout' => apply_filters( 'activitypub_remote_get_timeout', 100 ), 'limit_response_size' => 1048576, diff --git a/includes/class-migration.php b/includes/class-migration.php index 2e5f19c5..1ff8b663 100644 --- a/includes/class-migration.php +++ b/includes/class-migration.php @@ -1,6 +1,7 @@ 'ID' ) ) as $user_id ) { $followers = get_user_meta( $user_id, 'activitypub_followers', true ); @@ -72,6 +87,11 @@ class Migration { } } } + + // set the default username for the Blog User + if ( ! \get_option( 'activitypub_blog_user_identifier' ) ) { + \update_option( 'activitypub_blog_user_identifier', Blog_User::get_default_username() ); + } } /** diff --git a/includes/model/class-blog-user.php b/includes/model/class-blog-user.php index a0efcb64..feee0976 100644 --- a/includes/model/class-blog-user.php +++ b/includes/model/class-blog-user.php @@ -71,7 +71,7 @@ class Blog_User extends User { } /** - * Generate and save a default Username. + * Generate a default Username. * * @return string The auto-generated Username. */ @@ -105,9 +105,19 @@ class Blog_User extends User { // get random item of $default_identifier $default = $default_identifier[ \array_rand( $default_identifier ) ]; - return $default; + /** + * Filter the default blog username. + * + * @param string $default The default username. + */ + return apply_filters( 'activitypub_default_blog_username', $default ); } + /** + * Get the preferred User-Name. + * + * @return string The User-Name. + */ public function get_preferred_username() { $username = \get_option( 'activitypub_blog_user_identifier' ); @@ -118,6 +128,11 @@ class Blog_User extends User { return self::get_default_username(); } + /** + * Get the User-Icon. + * + * @return array|null The User-Icon. + */ public function get_icon() { $image = wp_get_attachment_image_src( get_theme_mod( 'custom_logo' ) ); @@ -131,6 +146,11 @@ class Blog_User extends User { return null; } + /** + * Get the User-Header-Image. + * + * @return array|null The User-Header-Image. + */ public function get_header_image() { if ( \has_header_image() ) { return array( @@ -175,6 +195,8 @@ class Blog_User extends User { } /** + * Get the User-Private-Key. + * * @param int $user_id * * @return mixed