some more checks if a blog is in single user mode or not
This commit is contained in:
parent
201ee16f37
commit
c288fbe021
1 changed files with 66 additions and 14 deletions
|
@ -1,6 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
namespace Activitypub;
|
namespace Activitypub;
|
||||||
|
|
||||||
|
use WP_Error;
|
||||||
use Activitypub\Http;
|
use Activitypub\Http;
|
||||||
use Activitypub\Activity\Activity;
|
use Activitypub\Activity\Activity;
|
||||||
use Activitypub\Collection\Followers;
|
use Activitypub\Collection\Followers;
|
||||||
|
@ -281,13 +282,6 @@ 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 ) {
|
||||||
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;
|
$return = false;
|
||||||
|
|
||||||
switch ( $user_id ) {
|
switch ( $user_id ) {
|
||||||
|
@ -297,8 +291,8 @@ function is_user_disabled( $user_id ) {
|
||||||
break;
|
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 ( is_user_type_disabled( 'blog' ) ) {
|
||||||
$return = ACTIVITYPUB_DISABLE_BLOG_USER;
|
$return = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -311,8 +305,8 @@ function is_user_disabled( $user_id ) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( defined( 'ACTIVITYPUB_DISABLE_USER' ) ) {
|
if ( is_user_type_disabled( 'user' ) ) {
|
||||||
$return = ACTIVITYPUB_DISABLE_USER;
|
$return = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -328,6 +322,60 @@ function is_user_disabled( $user_id ) {
|
||||||
return apply_filters( 'activitypub_is_user_disabled', $return, $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.
|
* Check if the blog is in single-user mode.
|
||||||
*
|
*
|
||||||
|
@ -336,9 +384,13 @@ function is_user_disabled( $user_id ) {
|
||||||
function is_single_user() {
|
function is_single_user() {
|
||||||
$return = false;
|
$return = false;
|
||||||
|
|
||||||
if (
|
if ( \defined( 'ACTIVITYPUB_SINGLE_USER_MODE' ) ) {
|
||||||
false === ACTIVITYPUB_DISABLE_BLOG_USER &&
|
if ( ACTIVITYPUB_SINGLE_USER_MODE ) {
|
||||||
true === ACTIVITYPUB_DISABLE_USER
|
$return = true;
|
||||||
|
}
|
||||||
|
} elseif (
|
||||||
|
false === is_user_type_disabled( 'blog' ) &&
|
||||||
|
true === is_user_type_disabled( 'user' )
|
||||||
) {
|
) {
|
||||||
$return = true;
|
$return = true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue