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.
|
* @return string The auto-generated Username.
|
||||||
*/
|
*/
|
||||||
public static function get_default_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
|
// check if domain host has a subdomain
|
||||||
$host = \wp_parse_url( \get_home_url(), \PHP_URL_HOST );
|
$host = \wp_parse_url( \get_home_url(), \PHP_URL_HOST );
|
||||||
$host = \preg_replace( '/^www\./i', '', $host );
|
$host = \preg_replace( '/^www\./i', '', $host );
|
||||||
$host_parts = \explode( '.', $host );
|
$host_parts = \explode( '.', $host );
|
||||||
|
|
||||||
if ( \count( $host_parts ) <= 2 && strlen( $host ) <= 15 ) {
|
if ( \count( $host_parts ) <= 2 && strlen( $host ) <= 15 ) {
|
||||||
\update_option( 'activitypub_blog_user_identifier', $host );
|
|
||||||
return $host;
|
return $host;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,7 +89,6 @@ class Blog_User extends User {
|
||||||
$blog_title = \sanitize_title( $blog_title );
|
$blog_title = \sanitize_title( $blog_title );
|
||||||
|
|
||||||
if ( strlen( $blog_title ) <= 15 ) {
|
if ( strlen( $blog_title ) <= 15 ) {
|
||||||
\update_option( 'activitypub_blog_user_identifier', $blog_title );
|
|
||||||
return $blog_title;
|
return $blog_title;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,12 +103,17 @@ class Blog_User extends User {
|
||||||
|
|
||||||
// get random item of $default_identifier
|
// get random item of $default_identifier
|
||||||
$default = $default_identifier[ \array_rand( $default_identifier ) ];
|
$default = $default_identifier[ \array_rand( $default_identifier ) ];
|
||||||
\update_option( 'activitypub_blog_user_identifier', $default );
|
|
||||||
|
|
||||||
return $default;
|
return $default;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function get_preferred_username() {
|
public function get_preferred_username() {
|
||||||
|
$username = \get_option( 'activitypub_blog_user_identifier' );
|
||||||
|
|
||||||
|
if ( $username ) {
|
||||||
|
return $username;
|
||||||
|
}
|
||||||
|
|
||||||
return self::get_default_username();
|
return self::get_default_username();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
<form method="post" action="options.php">
|
<form method="post" action="options.php">
|
||||||
<?php \settings_fields( 'activitypub' ); ?>
|
<?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>
|
<h3><?php \esc_html_e( 'Blog-User', 'activitypub' ); ?></h3>
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@
|
||||||
|
|
||||||
<?php \do_settings_fields( 'activitypub', 'blog-user' ); ?>
|
<?php \do_settings_fields( 'activitypub', 'blog-user' ); ?>
|
||||||
|
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
|
|
||||||
<h3><?php \esc_html_e( 'Activities', 'activitypub' ); ?></h3>
|
<h3><?php \esc_html_e( 'Activities', 'activitypub' ); ?></h3>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue