do not persist data in a getter!

This commit is contained in:
Matthias Pfefferle 2023-07-11 09:21:16 +02:00
parent a461ea3b1f
commit befd0d4f1e
2 changed files with 8 additions and 11 deletions

View file

@ -75,19 +75,12 @@ class Blog_User extends User {
* @return string The auto-generated Username.
*/
public static function get_default_username() {
$username = \get_option( 'activitypub_blog_user_identifier' );
if ( $username ) {
return $username;
}
// check if domain host has a subdomain
$host = \wp_parse_url( \get_home_url(), \PHP_URL_HOST );
$host = \preg_replace( '/^www\./i', '', $host );
$host_parts = \explode( '.', $host );
if ( \count( $host_parts ) <= 2 && strlen( $host ) <= 15 ) {
\update_option( 'activitypub_blog_user_identifier', $host );
return $host;
}
@ -96,7 +89,6 @@ class Blog_User extends User {
$blog_title = \sanitize_title( $blog_title );
if ( strlen( $blog_title ) <= 15 ) {
\update_option( 'activitypub_blog_user_identifier', $blog_title );
return $blog_title;
}
@ -111,12 +103,17 @@ class Blog_User extends User {
// get random item of $default_identifier
$default = $default_identifier[ \array_rand( $default_identifier ) ];
\update_option( 'activitypub_blog_user_identifier', $default );
return $default;
}
public function get_preferred_username() {
$username = \get_option( 'activitypub_blog_user_identifier' );
if ( $username ) {
return $username;
}
return self::get_default_username();
}

View file

@ -31,7 +31,7 @@
<form method="post" action="options.php">
<?php \settings_fields( 'activitypub' ); ?>
<?php if ( ! \Activitypub\is_user_disabled( \Activitypub\Collection\Users::BLOG_USER_ID ) ) : ?>
<?php if ( ! \Activitypub\is_user_disabled( \Activitypub\Collection\Users::BLOG_USER_ID ) ) : ?>
<h3><?php \esc_html_e( 'Blog-User', 'activitypub' ); ?></h3>
@ -58,7 +58,7 @@
<?php \do_settings_fields( 'activitypub', 'blog-user' ); ?>
<?php endif; ?>
<?php endif; ?>
<h3><?php \esc_html_e( 'Activities', 'activitypub' ); ?></h3>