some fixes based on the feedback of @mattwiebe

This commit is contained in:
Matthias Pfefferle 2023-07-11 08:53:18 +02:00
parent 8920c60c61
commit d5a389420d
4 changed files with 26 additions and 14 deletions

View file

@ -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
);
}
}

View file

@ -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;
}
}

View file

@ -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 ) {

View file

@ -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 );