do not persist data in a getter!
This commit is contained in:
parent
a461ea3b1f
commit
befd0d4f1e
2 changed files with 8 additions and 11 deletions
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue