some more checks if a blog is in single user mode or not

This commit is contained in:
Matthias Pfefferle 2023-07-20 10:57:14 +02:00
parent 201ee16f37
commit c288fbe021

View file

@ -1,6 +1,7 @@
<?php
namespace Activitypub;
use WP_Error;
use Activitypub\Http;
use Activitypub\Activity\Activity;
use Activitypub\Collection\Followers;
@ -281,13 +282,6 @@ function is_activitypub_request() {
* @return boolean True if the user is disabled, false otherwise.
*/
function is_user_disabled( $user_id ) {
if ( \defined( 'ACTIVITYPUB_SINGLE_USER_MODE' ) ) {
if ( ACTIVITYPUB_SINGLE_USER_MODE ) {
\defined( 'ACTIVITYPUB_DISABLE_USER' ) || \define( 'ACTIVITYPUB_DISABLE_USER', true );
\defined( 'ACTIVITYPUB_DISABLE_BLOG_USER' ) || \define( 'ACTIVITYPUB_DISABLE_BLOG_USER', false );
}
}
$return = false;
switch ( $user_id ) {
@ -297,8 +291,8 @@ function is_user_disabled( $user_id ) {
break;
// if the user is the blog user, it's only enabled in single-user mode.
case \Activitypub\Collection\Users::BLOG_USER_ID:
if ( defined( 'ACTIVITYPUB_DISABLE_BLOG_USER' ) ) {
$return = ACTIVITYPUB_DISABLE_BLOG_USER;
if ( is_user_type_disabled( 'blog' ) ) {
$return = true;
break;
}
@ -311,8 +305,8 @@ function is_user_disabled( $user_id ) {
break;
}
if ( defined( 'ACTIVITYPUB_DISABLE_USER' ) ) {
$return = ACTIVITYPUB_DISABLE_USER;
if ( is_user_type_disabled( 'user' ) ) {
$return = true;
break;
}
@ -328,6 +322,60 @@ function is_user_disabled( $user_id ) {
return apply_filters( 'activitypub_is_user_disabled', $return, $user_id );
}
/**
* Checks if a User-Type is disabled for ActivityPub.
*
* This function is used to check if the 'blog' or 'user'
* type is disabled for ActivityPub.
*
* @param enum $type Can be 'blog' or 'user'.
*
* @return boolean True if the user type is disabled, false otherwise.
*/
function is_user_type_disabled( $type ) {
switch ( $type ) {
case 'blog':
if ( \defined( 'ACTIVITYPUB_SINGLE_USER_MODE' ) ) {
if ( ACTIVITYPUB_SINGLE_USER_MODE ) {
$return = false;
break;
}
}
if ( \defined( 'ACTIVITYPUB_DISABLE_BLOG_USER' ) ) {
$return = ACTIVITYPUB_DISABLE_BLOG_USER;
break;
}
// @todo check user settings
$return = false;
break;
case 'user':
if ( \defined( 'ACTIVITYPUB_SINGLE_USER_MODE' ) ) {
if ( ACTIVITYPUB_SINGLE_USER_MODE ) {
$return = true;
break;
}
}
if ( \defined( 'ACTIVITYPUB_DISABLE_USER' ) ) {
$return = ACTIVITYPUB_DISABLE_USER;
break;
}
// @todo check user settings
$return = false;
break;
default:
$return = new WP_Error( 'activitypub_wrong_user_type', __( 'Wrong user type', 'activitypub' ) );
break;
}
return apply_filters( 'activitypub_is_user_type_disabled', $return, $type );
}
/**
* Check if the blog is in single-user mode.
*
@ -336,9 +384,13 @@ function is_user_disabled( $user_id ) {
function is_single_user() {
$return = false;
if (
false === ACTIVITYPUB_DISABLE_BLOG_USER &&
true === ACTIVITYPUB_DISABLE_USER
if ( \defined( 'ACTIVITYPUB_SINGLE_USER_MODE' ) ) {
if ( ACTIVITYPUB_SINGLE_USER_MODE ) {
$return = true;
}
} elseif (
false === is_user_type_disabled( 'blog' ) &&
true === is_user_type_disabled( 'user' )
) {
$return = true;
}