make is_user_disabled filterable

This commit is contained in:
Matthias Pfefferle 2023-07-11 08:58:50 +02:00
parent d5a389420d
commit 0ab61b6441

View file

@ -281,29 +281,39 @@ function is_activitypub_request() {
* @return boolean True if the user is disabled, false otherwise. * @return boolean True if the user is disabled, false otherwise.
*/ */
function is_user_disabled( $user_id ) { function is_user_disabled( $user_id ) {
$return = false;
switch ( $user_id ) { switch ( $user_id ) {
// if the user is the application user, it's always enabled. // if the user is the application user, it's always enabled.
case \Activitypub\Collection\Users::APPLICATION_USER_ID: case \Activitypub\Collection\Users::APPLICATION_USER_ID:
return false; $return = false;
break;
// if the user is the blog user, it's only enabled in single-user mode. // if the user is the blog user, it's only enabled in single-user mode.
case \Activitypub\Collection\Users::BLOG_USER_ID: case \Activitypub\Collection\Users::BLOG_USER_ID:
if ( defined( 'ACTIVITYPUB_DISABLE_BLOG_USER' ) ) { if ( defined( 'ACTIVITYPUB_DISABLE_BLOG_USER' ) ) {
return ACTIVITYPUB_DISABLE_BLOG_USER; $return = ACTIVITYPUB_DISABLE_BLOG_USER;
break;
} }
return false; $return = false;
break;
// if the user is any other user, it's enabled if it can publish posts. // if the user is any other user, it's enabled if it can publish posts.
default: default:
if ( defined( 'ACTIVITYPUB_DISABLE_USER' ) ) { if ( defined( 'ACTIVITYPUB_DISABLE_USER' ) ) {
return ACTIVITYPUB_DISABLE_USER; $return = ACTIVITYPUB_DISABLE_USER;
break;
} }
if ( ! \user_can( $user_id, 'publish_posts' ) ) { if ( ! \user_can( $user_id, 'publish_posts' ) ) {
return true; $return = true;
break;
} }
return false; $return = false;
break;
} }
return apply_filters( 'activitypub_is_user_disabled', $return, $user_id );
} }
/** /**