diff --git a/includes/collection/class-followers.php b/includes/collection/class-followers.php index 449dd78..af0156e 100644 --- a/includes/collection/class-followers.php +++ b/includes/collection/class-followers.php @@ -484,11 +484,16 @@ class Followers { } /** - * Undocumented function + * This function is used to store errors that occur when + * sending an ActivityPub message to a Follower. * - * @param [type] $post_id - * @param [type] $error - * @return void + * The error will be stored in the + * post meta. + * + * @param int $post_id The ID of the WordPress Custom-Post-Type. + * @param mixed $error The error message. Can be a string or a WP_Error. + * + * @return int|false The meta ID on success, false on failure. */ public static function add_error( $post_id, $error ) { if ( is_string( $error ) ) { @@ -496,9 +501,16 @@ class Followers { } elseif ( is_wp_error( $error ) ) { $error_message = $error->get_error_message(); } else { - $error_message = __( 'Unknown Error or misconfigured Error-Message', 'activitypub' ); + $error_message = __( + 'Unknown Error or misconfigured Error-Message', + 'activitypub' + ); } - return add_post_meta( $post_id, 'activitypub_errors', $error_message ); + return add_post_meta( + $post_id, + 'activitypub_errors', + $error_message + ); } } diff --git a/includes/functions.php b/includes/functions.php index 0c3dc70..05e14b9 100644 --- a/includes/functions.php +++ b/includes/functions.php @@ -294,14 +294,14 @@ function is_user_disabled( $user_id ) { return false; // if the user is any other user, it's enabled if it can publish posts. default: - if ( ! \user_can( $user_id, 'publish_posts' ) ) { - return true; - } - if ( defined( 'ACTIVITYPUB_DISABLE_USER' ) ) { return ACTIVITYPUB_DISABLE_USER; } + if ( ! \user_can( $user_id, 'publish_posts' ) ) { + return true; + } + return false; } } diff --git a/includes/model/class-blog-user.php b/includes/model/class-blog-user.php index a1f1be3..d1413dc 100644 --- a/includes/model/class-blog-user.php +++ b/includes/model/class-blog-user.php @@ -83,7 +83,7 @@ class Blog_User extends User { // check if domain host has a subdomain $host = \wp_parse_url( \get_home_url(), \PHP_URL_HOST ); - $host = \str_replace( 'www.', '', $host ); + $host = \preg_replace( '/^www\./i', '', $host ); $host_parts = \explode( '.', $host ); if ( \count( $host_parts ) <= 2 && strlen( $host ) <= 15 ) { diff --git a/includes/rest/class-followers.php b/includes/rest/class-followers.php index 9b9ed89..cdff551 100644 --- a/includes/rest/class-followers.php +++ b/includes/rest/class-followers.php @@ -6,7 +6,7 @@ use stdClass; use WP_REST_Server; use WP_REST_Response; use Activitypub\Collection\Users as User_Collection; -use Activitypub\Collection\Followers as FollowerCollection; +use Activitypub\Collection\Followers as Follower_Collection; use function Activitypub\get_rest_url_by_path; @@ -74,7 +74,7 @@ class Followers { $json->actor = $user->get_id(); $json->type = 'OrderedCollectionPage'; - $json->totalItems = FollowerCollection::count_followers( $user->get__id() ); // phpcs:ignore + $json->totalItems = Follower_Collection::count_followers( $user->get__id() ); // phpcs:ignore $json->partOf = get_rest_url_by_path( sprintf( 'users/%d/followers', $user->get__id() ) ); // phpcs:ignore $json->first = \add_query_arg( 'page', 1, $json->partOf ); // phpcs:ignore @@ -93,7 +93,7 @@ class Followers { function( $item ) { return $item->get_url(); }, - FollowerCollection::get_followers( $user->get__id(), 20, $page ) + Follower_Collection::get_followers( $user->get__id(), 20, $page ) ); $response = new WP_REST_Response( $json, 200 );